Skip to content

Commit b862776

Browse files
TheNumbatmshinwell
andauthored
flambda-backend: Add 5.x systhreads code (#2015)
* Remove duplicate definition of exit in thread.ml * git mv systhreads systhreads4 * Import otherlibs/systhreads/ from upstream tree at rev a784056 (tag tip-5 in ocaml-jst) as ocaml/otherlibs/systhreads5/ * Autogenerate otherlibs/dune to switch between systhreads implementations * Actually call systhreads5/ just systhreads/ * Initial version of systhreads/dune * Fix upstream systhreads build * fix builds * now it needs suffix for setup * fix unquoted yes --------- Co-authored-by: Mark Shinwell <mshinwell@pm.me>
1 parent ab968a0 commit b862776

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4304
-2077
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,4 @@ META
360360
/otherlibs/dynlink/natdynlinkops
361361

362362
dune.runtime_selection
363-
363+
/otherlibs/dune

Makefile.common

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ endif # ifeq "$(wildcard $(ROOTDIR)/flexlink.opt$(EXE))" ""
140140
endif # ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
141141

142142
# List of other libraries
143-
ALL_OTHERLIBS = dynlink str systhreads unix runtime_events
143+
ALL_OTHERLIBS = dynlink str systhreads$(RUNTIME_SUFFIX) unix runtime_events
144144

145145
# Flags to pass to the C preprocessor when preprocessing assembly files
146146
OC_ASPPFLAGS=$(OC_CPPFLAGS) $(OC_NATIVE_CPPFLAGS)

Makefile.common-jst

+10-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ dune_config_targets = \
110110
$(ocamldir)/duneconf/jst-extra.inc \
111111
dune-project \
112112
$(ocamldir)/stdlib/ocaml_compiler_internal_params \
113-
$(ocamldir)/dune.runtime_selection
113+
$(ocamldir)/dune.runtime_selection \
114+
$(ocamldir)/otherlibs/dune
115+
116+
$(ocamldir)/otherlibs/dune:
117+
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
118+
echo "(dirs (:standard \ systhreads))" > $@; \
119+
else \
120+
echo "(dirs (:standard \ systhreads4))" > $@; \
121+
fi
114122

115123
$(ocamldir)/dune.runtime_selection:
116124
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
@@ -242,7 +250,7 @@ install_for_test: _install
242250
ln -s . lex; ln -s . yacc; \
243251
ln -s _install/lib/ocaml/compiler-libs compilerlibs; \
244252
mkdir -p otherlibs/{unix,dynlink/native,str,bigarray}; \
245-
ln -s ../stdlib/threads otherlibs/systhreads; \
253+
ln -s ../stdlib/threads otherlibs/systhreads$(RUNTIME_SUFFIX); \
246254
$(cpl) stdlib/unix/{lib,}unix* otherlibs/unix; \
247255
$(cpl) stdlib/dynlink/dynlink* otherlibs/dynlink; \
248256
$(cpl) stdlib/str/{lib,}str* otherlibs/str; \

configure

+12-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+11-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ flexdll_dir=
6969
lib_dynlink=false
7070
lib_str=false
7171
lib_systhreads=false
72+
lib_systhreads_path=""
7273
lib_unix=false
7374
ocamltest_libunix=None
7475
ocamltest_unix_impl="dummy"
@@ -170,6 +171,7 @@ AC_SUBST([lib_dynlink])
170171
AC_SUBST([lib_runtime_events])
171172
AC_SUBST([lib_str])
172173
AC_SUBST([lib_systhreads])
174+
AC_SUBST([lib_systhreads_path])
173175
AC_SUBST([lib_unix])
174176
AC_SUBST([ocamltest_CPP])
175177
AC_SUBST([ocamltest_libunix])
@@ -2116,6 +2118,12 @@ AS_CASE([$host],
21162118

21172119
## Activate the systhread library
21182120

2121+
if [ "$enable_runtime5" = "yes" ]; then
2122+
runtime_suffix=
2123+
else
2124+
runtime_suffix=4
2125+
fi
2126+
21192127
AS_CASE([$enable_systhreads,$enable_unix_lib],
21202128
[yes,no],
21212129
[systhread_support=false
@@ -2124,9 +2132,10 @@ AS_CASE([$enable_systhreads,$enable_unix_lib],
21242132
[systhread_support=false
21252133
AC_MSG_NOTICE([the threads library is disabled])],
21262134
[systhread_support=true
2127-
AC_CONFIG_FILES([otherlibs/systhreads/META])
2128-
otherlibraries="$otherlibraries systhreads"
2135+
AC_CONFIG_FILES([otherlibs/systhreads${runtime_suffix}/META])
2136+
otherlibraries="$otherlibraries systhreads${runtime_suffix}"
21292137
lib_systhreads=true
2138+
lib_systhreads_path="systhreads${runtime_suffix}"
21302139
AC_MSG_NOTICE([the threads library is supported])])
21312140

21322141
## Does the assembler support debug prefix map and CFI directives

ocamltest/ocaml_modifiers.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let str = make_library_modifier
9696
let systhreads =
9797
unix @
9898
(make_library_modifier
99-
"threads" [compiler_subdir ["otherlibs"; "systhreads"]])
99+
"threads" [compiler_subdir ["otherlibs"; Ocamltest_config.systhreads_path]])
100100

101101
let runtime_events =
102102
make_library_modifier

ocamltest/ocamltest_config.ml.in

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ let libunix = @ocamltest_libunix@
3838

3939
let systhreads = @lib_systhreads@
4040

41+
let systhreads_path = {@QS@|@lib_systhreads_path@|@QS@}
42+
4143
let str = @lib_str@
4244

4345
let objext = {@QS@|@OBJEXT@|@QS@}

ocamltest/ocamltest_config.mli

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ val libunix : bool option
4949
val systhreads : bool
5050
(** Indicates whether systhreads is available. *)
5151

52+
val systhreads_path : string
53+
(** Indicates where the systhreads library is installed under otherlibs/. *)
54+
5255
val str : bool
5356
(** Indicates whether str is available. *)
5457

otherlibs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include $(ROOTDIR)/Makefile.common
2121
# at the moment, the clean targets depend on this variable but
2222
# when they are invoked ../Makefile.config is not included, so that
2323
# OTHERLIBRARIES would be empty and the clean targets would thus not work.
24-
OTHERLIBRARIES ?= dynlink str systhreads unix runtime_events
24+
OTHERLIBRARIES ?= dynlink str systhreads$(RUNTIME_SUFFIX) unix runtime_events
2525

2626
# $1: target name to dispatch to all otherlibs/*/Makefile
2727
define dispatch_

otherlibs/systhreads/.depend

-26
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
1-
condition.cmo : \
2-
mutex.cmi \
3-
condition.cmi
4-
condition.cmx : \
5-
mutex.cmx \
6-
condition.cmi
7-
condition.cmi : \
8-
mutex.cmi
91
event.cmo : \
10-
mutex.cmi \
11-
condition.cmi \
122
event.cmi
133
event.cmx : \
14-
mutex.cmx \
15-
condition.cmx \
164
event.cmi
175
event.cmi :
18-
mutex.cmo : \
19-
mutex.cmi
20-
mutex.cmx : \
21-
mutex.cmi
22-
mutex.cmi :
23-
semaphore.cmo : \
24-
mutex.cmi \
25-
condition.cmi \
26-
semaphore.cmi
27-
semaphore.cmx : \
28-
mutex.cmx \
29-
condition.cmx \
30-
semaphore.cmi
31-
semaphore.cmi :
326
thread.cmo : \
337
thread.cmi
348
thread.cmx : \

otherlibs/systhreads/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ifneq "$(CCOMPTYPE)" "msvc"
2222
OC_CFLAGS += -g
2323
endif
2424

25-
OC_CFLAGS += $(SHAREDLIB_CFLAGS) $(PTHREAD_CFLAGS)
25+
OC_CFLAGS += $(SHAREDLIB_CFLAGS)
2626

2727
LIBS = $(STDLIBFLAGS) -I $(ROOTDIR)/otherlibs/unix
2828

@@ -45,12 +45,12 @@ LIBNAME=threads
4545
BYTECODE_C_OBJS=st_stubs.b.$(O)
4646
NATIVECODE_C_OBJS=st_stubs.n.$(O)
4747

48-
THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml semaphore.ml
48+
THREADS_SOURCES = thread.ml event.ml
4949

5050
THREADS_BCOBJS = $(THREADS_SOURCES:.ml=.cmo)
5151
THREADS_NCOBJS = $(THREADS_SOURCES:.ml=.cmx)
5252

53-
MLIFILES=thread.mli mutex.mli condition.mli event.mli semaphore.mli
53+
MLIFILES=thread.mli event.mli
5454

5555
CMIFILES=$(MLIFILES:.mli=.cmi)
5656

@@ -61,7 +61,7 @@ allopt: lib$(LIBNAME)nat.$(A) $(LIBNAME).cmxa $(CMIFILES)
6161
lib$(LIBNAME).$(A): $(BYTECODE_C_OBJS)
6262
$(V_OCAMLMKLIB)$(MKLIB_CMD) -o $(LIBNAME) $(BYTECODE_C_OBJS)
6363

64-
lib$(LIBNAME)nat.$(A): OC_CFLAGS += $(OC_NATIVE_CFLAGS) -DNATIVE_CODE
64+
lib$(LIBNAME)nat.$(A): OC_CFLAGS += $(OC_NATIVE_CFLAGS)
6565

6666
lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS)
6767
$(V_OCAMLMKLIB)$(MKLIB_CMD) -o $(LIBNAME)nat $^

otherlibs/systhreads/dune

+16-41
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,22 @@
1212
;* *
1313
;**************************************************************************
1414

15-
1615
; For some reason the C header files aren't being found if this library
1716
; is given a public name, so we do the installation manually.
18-
(install
19-
(files
20-
(byte/threads.cma as threads/threads.cma)
21-
(native/threadsnat.cmxa as threads/threads.cmxa)
22-
(native/threadsnat.a as threads/threads.a)
23-
24-
(byte/libthreads_stubs.a as libthreads_stubs.a)
25-
(byte/dllthreads_stubs.so as stublibs/dllthreads_stubs.so)
26-
(native/libthreadsnat_stubs.a as libthreadsnat_stubs.a)
27-
(native/libthreadsnat_stubs.a as libthreadsnat_stubs_native.a) ; for special_dune compat
28-
29-
30-
(thread.mli as threads/thread.mli)
31-
(condition.mli as threads/condition.mli)
32-
(event.mli as threads/event.mli)
33-
(mutex.mli as threads/mutex.mli)
34-
(semaphore.mli as threads/semaphore.mli)
35-
36-
(threads.h as caml/threads.h)
37-
38-
(native/.threadsnat.objs/native/condition.cmx as threads/condition.cmx)
39-
(native/.threadsnat.objs/native/event.cmx as threads/event.cmx)
40-
(native/.threadsnat.objs/native/mutex.cmx as threads/mutex.cmx)
41-
(native/.threadsnat.objs/native/semaphore.cmx as threads/semaphore.cmx)
42-
(native/.threadsnat.objs/native/thread.cmx as threads/thread.cmx)
43-
44-
(byte/.threads.objs/byte/condition.cmi as threads/condition.cmi)
45-
(byte/.threads.objs/byte/condition.cmti as threads/condition.cmti)
46-
(byte/.threads.objs/byte/event.cmi as threads/event.cmi)
47-
(byte/.threads.objs/byte/event.cmti as threads/event.cmti)
48-
(byte/.threads.objs/byte/mutex.cmi as threads/mutex.cmi)
49-
(byte/.threads.objs/byte/mutex.cmti as threads/mutex.cmti)
50-
(byte/.threads.objs/byte/semaphore.cmi as threads/semaphore.cmi)
51-
(byte/.threads.objs/byte/semaphore.cmti as threads/semaphore.cmti)
52-
(byte/.threads.objs/byte/thread.cmi as threads/thread.cmi)
53-
(byte/.threads.objs/byte/thread.cmti as threads/thread.cmti)
54-
)
55-
(section lib)
56-
(package ocaml))
57-
5817

18+
(install
19+
(files
20+
(byte/threads.cma as threads/threads.cma)
21+
(native/threadsnat.cmxa as threads/threads.cmxa)
22+
(native/threadsnat.a as threads/threads.a)
23+
(byte/libthreads_stubs.a as libthreads_stubs.a)
24+
(byte/dllthreads_stubs.so as stublibs/dllthreads_stubs.so)
25+
(native/libthreadsnat_stubs.a as libthreadsnat_stubs.a)
26+
(native/libthreadsnat_stubs.a as libthreadsnat_stubs_native.a) ; for special_dune compat
27+
(thread.mli as threads/thread.mli)
28+
(threads.h as caml/threads.h)
29+
(native/.threadsnat.objs/native/thread.cmx as threads/thread.cmx)
30+
(byte/.threads.objs/byte/thread.cmi as threads/thread.cmi)
31+
(byte/.threads.objs/byte/thread.cmti as threads/thread.cmti))
32+
(section lib)
33+
(package ocaml))

otherlibs/systhreads/event.ml

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
(* *)
1414
(**************************************************************************)
1515

16-
[@@@ocaml.flambda_o3]
17-
1816
(* Events *)
1917
type 'a basic_event =
2018
{ poll: unit -> bool;

0 commit comments

Comments
 (0)