Skip to content

Add 5.x systhreads code #2015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocaml/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,4 @@ META
/otherlibs/dynlink/natdynlinkops

dune.runtime_selection

/otherlibs/dune
2 changes: 1 addition & 1 deletion ocaml/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ endif # ifeq "$(wildcard $(ROOTDIR)/flexlink.opt$(EXE))" ""
endif # ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"

# List of other libraries
ALL_OTHERLIBS = dynlink str systhreads unix runtime_events
ALL_OTHERLIBS = dynlink str systhreads$(RUNTIME_SUFFIX) unix runtime_events

# Flags to pass to the C preprocessor when preprocessing assembly files
OC_ASPPFLAGS=$(OC_CPPFLAGS) $(OC_NATIVE_CPPFLAGS)
Expand Down
12 changes: 10 additions & 2 deletions ocaml/Makefile.common-jst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ dune_config_targets = \
$(ocamldir)/duneconf/jst-extra.inc \
dune-project \
$(ocamldir)/stdlib/ocaml_compiler_internal_params \
$(ocamldir)/dune.runtime_selection
$(ocamldir)/dune.runtime_selection \
$(ocamldir)/otherlibs/dune

$(ocamldir)/otherlibs/dune:
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
echo "(dirs (:standard \ systhreads))" > $@; \
else \
echo "(dirs (:standard \ systhreads4))" > $@; \
fi

$(ocamldir)/dune.runtime_selection:
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
Expand Down Expand Up @@ -242,7 +250,7 @@ install_for_test: _install
ln -s . lex; ln -s . yacc; \
ln -s _install/lib/ocaml/compiler-libs compilerlibs; \
mkdir -p otherlibs/{unix,dynlink/native,str,bigarray}; \
ln -s ../stdlib/threads otherlibs/systhreads; \
ln -s ../stdlib/threads otherlibs/systhreads$(RUNTIME_SUFFIX); \
$(cpl) stdlib/unix/{lib,}unix* otherlibs/unix; \
$(cpl) stdlib/dynlink/dynlink* otherlibs/dynlink; \
$(cpl) stdlib/str/{lib,}str* otherlibs/str; \
Expand Down
16 changes: 12 additions & 4 deletions ocaml/configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions ocaml/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ flexdll_dir=
lib_dynlink=false
lib_str=false
lib_systhreads=false
lib_systhreads_path=""
lib_unix=false
ocamltest_libunix=None
ocamltest_unix_impl="dummy"
Expand Down Expand Up @@ -170,6 +171,7 @@ AC_SUBST([lib_dynlink])
AC_SUBST([lib_runtime_events])
AC_SUBST([lib_str])
AC_SUBST([lib_systhreads])
AC_SUBST([lib_systhreads_path])
AC_SUBST([lib_unix])
AC_SUBST([ocamltest_CPP])
AC_SUBST([ocamltest_libunix])
Expand Down Expand Up @@ -2116,6 +2118,12 @@ AS_CASE([$host],

## Activate the systhread library

if [ "$enable_runtime5" = "yes" ]; then
runtime_suffix=
else
runtime_suffix=4
fi

AS_CASE([$enable_systhreads,$enable_unix_lib],
[yes,no],
[systhread_support=false
Expand All @@ -2124,9 +2132,10 @@ AS_CASE([$enable_systhreads,$enable_unix_lib],
[systhread_support=false
AC_MSG_NOTICE([the threads library is disabled])],
[systhread_support=true
AC_CONFIG_FILES([otherlibs/systhreads/META])
otherlibraries="$otherlibraries systhreads"
AC_CONFIG_FILES([otherlibs/systhreads${runtime_suffix}/META])
otherlibraries="$otherlibraries systhreads${runtime_suffix}"
lib_systhreads=true
lib_systhreads_path="systhreads${runtime_suffix}"
AC_MSG_NOTICE([the threads library is supported])])

## Does the assembler support debug prefix map and CFI directives
Expand Down
2 changes: 1 addition & 1 deletion ocaml/ocamltest/ocaml_modifiers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let str = make_library_modifier
let systhreads =
unix @
(make_library_modifier
"threads" [compiler_subdir ["otherlibs"; "systhreads"]])
"threads" [compiler_subdir ["otherlibs"; Ocamltest_config.systhreads_path]])

let runtime_events =
make_library_modifier
Expand Down
2 changes: 2 additions & 0 deletions ocaml/ocamltest/ocamltest_config.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ let libunix = @ocamltest_libunix@

let systhreads = @lib_systhreads@

let systhreads_path = {@QS@|@lib_systhreads_path@|@QS@}

let str = @lib_str@

let objext = {@QS@|@OBJEXT@|@QS@}
Expand Down
3 changes: 3 additions & 0 deletions ocaml/ocamltest/ocamltest_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ val libunix : bool option
val systhreads : bool
(** Indicates whether systhreads is available. *)

val systhreads_path : string
(** Indicates where the systhreads library is installed under otherlibs/. *)

val str : bool
(** Indicates whether str is available. *)

Expand Down
2 changes: 1 addition & 1 deletion ocaml/otherlibs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include $(ROOTDIR)/Makefile.common
# at the moment, the clean targets depend on this variable but
# when they are invoked ../Makefile.config is not included, so that
# OTHERLIBRARIES would be empty and the clean targets would thus not work.
OTHERLIBRARIES ?= dynlink str systhreads unix runtime_events
OTHERLIBRARIES ?= dynlink str systhreads$(RUNTIME_SUFFIX) unix runtime_events

# $1: target name to dispatch to all otherlibs/*/Makefile
define dispatch_
Expand Down
26 changes: 0 additions & 26 deletions ocaml/otherlibs/systhreads/.depend
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
condition.cmo : \
mutex.cmi \
condition.cmi
condition.cmx : \
mutex.cmx \
condition.cmi
condition.cmi : \
mutex.cmi
event.cmo : \
mutex.cmi \
condition.cmi \
event.cmi
event.cmx : \
mutex.cmx \
condition.cmx \
event.cmi
event.cmi :
mutex.cmo : \
mutex.cmi
mutex.cmx : \
mutex.cmi
mutex.cmi :
semaphore.cmo : \
mutex.cmi \
condition.cmi \
semaphore.cmi
semaphore.cmx : \
mutex.cmx \
condition.cmx \
semaphore.cmi
semaphore.cmi :
thread.cmo : \
thread.cmi
thread.cmx : \
Expand Down
8 changes: 4 additions & 4 deletions ocaml/otherlibs/systhreads/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ifneq "$(CCOMPTYPE)" "msvc"
OC_CFLAGS += -g
endif

OC_CFLAGS += $(SHAREDLIB_CFLAGS) $(PTHREAD_CFLAGS)
OC_CFLAGS += $(SHAREDLIB_CFLAGS)

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

Expand All @@ -45,12 +45,12 @@ LIBNAME=threads
BYTECODE_C_OBJS=st_stubs.b.$(O)
NATIVECODE_C_OBJS=st_stubs.n.$(O)

THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml semaphore.ml
THREADS_SOURCES = thread.ml event.ml

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

MLIFILES=thread.mli mutex.mli condition.mli event.mli semaphore.mli
MLIFILES=thread.mli event.mli

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

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

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

lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS)
$(V_OCAMLMKLIB)$(MKLIB_CMD) -o $(LIBNAME)nat $^
Expand Down
57 changes: 16 additions & 41 deletions ocaml/otherlibs/systhreads/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,22 @@
;* *
;**************************************************************************


; For some reason the C header files aren't being found if this library
; is given a public name, so we do the installation manually.
(install
(files
(byte/threads.cma as threads/threads.cma)
(native/threadsnat.cmxa as threads/threads.cmxa)
(native/threadsnat.a as threads/threads.a)

(byte/libthreads_stubs.a as libthreads_stubs.a)
(byte/dllthreads_stubs.so as stublibs/dllthreads_stubs.so)
(native/libthreadsnat_stubs.a as libthreadsnat_stubs.a)
(native/libthreadsnat_stubs.a as libthreadsnat_stubs_native.a) ; for special_dune compat


(thread.mli as threads/thread.mli)
(condition.mli as threads/condition.mli)
(event.mli as threads/event.mli)
(mutex.mli as threads/mutex.mli)
(semaphore.mli as threads/semaphore.mli)

(threads.h as caml/threads.h)

(native/.threadsnat.objs/native/condition.cmx as threads/condition.cmx)
(native/.threadsnat.objs/native/event.cmx as threads/event.cmx)
(native/.threadsnat.objs/native/mutex.cmx as threads/mutex.cmx)
(native/.threadsnat.objs/native/semaphore.cmx as threads/semaphore.cmx)
(native/.threadsnat.objs/native/thread.cmx as threads/thread.cmx)

(byte/.threads.objs/byte/condition.cmi as threads/condition.cmi)
(byte/.threads.objs/byte/condition.cmti as threads/condition.cmti)
(byte/.threads.objs/byte/event.cmi as threads/event.cmi)
(byte/.threads.objs/byte/event.cmti as threads/event.cmti)
(byte/.threads.objs/byte/mutex.cmi as threads/mutex.cmi)
(byte/.threads.objs/byte/mutex.cmti as threads/mutex.cmti)
(byte/.threads.objs/byte/semaphore.cmi as threads/semaphore.cmi)
(byte/.threads.objs/byte/semaphore.cmti as threads/semaphore.cmti)
(byte/.threads.objs/byte/thread.cmi as threads/thread.cmi)
(byte/.threads.objs/byte/thread.cmti as threads/thread.cmti)
)
(section lib)
(package ocaml))


(install
(files
(byte/threads.cma as threads/threads.cma)
(native/threadsnat.cmxa as threads/threads.cmxa)
(native/threadsnat.a as threads/threads.a)
(byte/libthreads_stubs.a as libthreads_stubs.a)
(byte/dllthreads_stubs.so as stublibs/dllthreads_stubs.so)
(native/libthreadsnat_stubs.a as libthreadsnat_stubs.a)
(native/libthreadsnat_stubs.a as libthreadsnat_stubs_native.a) ; for special_dune compat
(thread.mli as threads/thread.mli)
(threads.h as caml/threads.h)
(native/.threadsnat.objs/native/thread.cmx as threads/thread.cmx)
(byte/.threads.objs/byte/thread.cmi as threads/thread.cmi)
(byte/.threads.objs/byte/thread.cmti as threads/thread.cmti))
(section lib)
(package ocaml))
2 changes: 0 additions & 2 deletions ocaml/otherlibs/systhreads/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
(* *)
(**************************************************************************)

[@@@ocaml.flambda_o3]

(* Events *)
type 'a basic_event =
{ poll: unit -> bool;
Expand Down
Loading