From e865f5920d4c6a53ee12cc1dc5c939f7d6414f93 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Thu, 31 Oct 2019 01:33:50 -0400 Subject: [PATCH] [runtime] Add a --enable-minimal=threads configure option to disable threading support. Use it on wasm. (mono/mono#17611) Commit migrated from https://github.com/mono/mono/commit/dc76a95aa9d266c0c9611408b00e63dfeca214b5 --- src/mono/configure.ac | 7 +++- src/mono/mono/utils/mono-coop-mutex.h | 79 ++++++++++++++++++++++++++++++++++- src/mono/mono/utils/mono-os-mutex.h | 42 +++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/src/mono/configure.ac b/src/mono/configure.ac index 7ab5aa4..12c7048 100644 --- a/src/mono/configure.ac +++ b/src/mono/configure.ac @@ -1752,7 +1752,7 @@ AM_CONDITIONAL(ENABLE_STATIC_GCC_LIBS, test "x$enable_static_gcc_libs" = "xyes") AC_ARG_ENABLE(minimal, [ --enable-minimal=LIST drop support for LIST subsystems. LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, dllmap, reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, interpreter, simd, soft_debug, perfcounters, normalization, desktop_loader, shared_perfcounters, remoting, - security, lldb, mdb, assert_messages, cleanup, sgen_marksweep_conc, sgen_split_nursery, sgen_gc_bridge, sgen_debug_helpers, sockets, gac.], + security, lldb, mdb, assert_messages, cleanup, sgen_marksweep_conc, sgen_split_nursery, sgen_gc_bridge, sgen_debug_helpers, sockets, gac, threads.], [ for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do eval "mono_feature_disable_$feature='yes'" @@ -1969,6 +1969,11 @@ if test "x$mono_feature_disable_dllmap" = "xyes"; then AC_MSG_NOTICE([Disabled DllMap in the loader.]) fi +if test "x$mono_feature_disable_threads" = "xyes"; then + AC_DEFINE(DISABLE_THREADS, 1, [Disable Threads]) + AC_MSG_NOTICE([Disabled threading support]) +fi + AC_ARG_ENABLE(executables, [ --disable-executables disable the build of the runtime executables], enable_executables=$enableval, enable_executables=yes) AM_CONDITIONAL(DISABLE_EXECUTABLES, test x$enable_executables = xno) diff --git a/src/mono/mono/utils/mono-coop-mutex.h b/src/mono/mono/utils/mono-coop-mutex.h index 2aa9bc6..61b62ac 100644 --- a/src/mono/mono/utils/mono-coop-mutex.h +++ b/src/mono/mono/utils/mono-coop-mutex.h @@ -15,11 +15,14 @@ * we use mono_os_(mutex|cond|sem)_... on MonoCoop(Mutex|Cond|Sem) structures */ typedef struct _MonoCoopMutex MonoCoopMutex; +typedef struct _MonoCoopCond MonoCoopCond; + +#ifndef DISABLE_THREADS + struct _MonoCoopMutex { mono_mutex_t m; }; -typedef struct _MonoCoopCond MonoCoopCond; struct _MonoCoopCond { mono_cond_t c; }; @@ -130,4 +133,78 @@ mono_coop_cond_broadcast (MonoCoopCond *cond) MONO_EXIT_GC_SAFE; } +#else /* DISABLE_THREADS */ + +struct _MonoCoopMutex { + int dummy; +}; + +struct _MonoCoopCond { + int dummy; +}; + +static inline void +mono_coop_mutex_init (MonoCoopMutex *mutex) +{ +} + +static inline void +mono_coop_mutex_init_recursive (MonoCoopMutex *mutex) +{ +} + +static inline void +mono_coop_mutex_destroy (MonoCoopMutex *mutex) +{ +} + +static inline void +mono_coop_mutex_lock (MonoCoopMutex *mutex) +{ +} + +static inline gint +mono_coop_mutex_trylock (MonoCoopMutex *mutex) +{ + return 0; +} + +static inline void +mono_coop_mutex_unlock (MonoCoopMutex *mutex) +{ +} + +static inline void +mono_coop_cond_init (MonoCoopCond *cond) +{ +} + +static inline void +mono_coop_cond_destroy (MonoCoopCond *cond) +{ +} + +static inline void +mono_coop_cond_wait (MonoCoopCond *cond, MonoCoopMutex *mutex) +{ +} + +static inline gint +mono_coop_cond_timedwait (MonoCoopCond *cond, MonoCoopMutex *mutex, guint32 timeout_ms) +{ + return 0; +} + +static inline void +mono_coop_cond_signal (MonoCoopCond *cond) +{ +} + +static inline void +mono_coop_cond_broadcast (MonoCoopCond *cond) +{ +} + +#endif /* DISABLE_THREADS */ + #endif /* __MONO_COOP_MUTEX_H__ */ diff --git a/src/mono/mono/utils/mono-os-mutex.h b/src/mono/mono/utils/mono-os-mutex.h index d2a466e..f26e9d8 100644 --- a/src/mono/mono/utils/mono-os-mutex.h +++ b/src/mono/mono/utils/mono-os-mutex.h @@ -43,6 +43,8 @@ typedef pthread_mutex_t mono_mutex_t; typedef pthread_cond_t mono_cond_t; +#ifndef DISABLE_THREADS + static inline void mono_os_mutex_init_type (mono_mutex_t *mutex, int type) { @@ -127,6 +129,46 @@ mono_os_mutex_unlock (mono_mutex_t *mutex) g_error ("%s: pthread_mutex_unlock failed with \"%s\" (%d)", __func__, g_strerror (res), res); } +#else /* DISABLE_THREADS */ + +static inline void +mono_os_mutex_init_type (mono_mutex_t *mutex, int type) +{ +} + +static inline void +mono_os_mutex_init (mono_mutex_t *mutex) +{ +} + +static inline void +mono_os_mutex_init_recursive (mono_mutex_t *mutex) +{ +} + +static inline void +mono_os_mutex_destroy (mono_mutex_t *mutex) +{ +} + +static inline void +mono_os_mutex_lock (mono_mutex_t *mutex) +{ +} + +static inline int +mono_os_mutex_trylock (mono_mutex_t *mutex) +{ + return 0; +} + +static inline void +mono_os_mutex_unlock (mono_mutex_t *mutex) +{ +} + +#endif /* DISABLE_THREADS */ + static inline void mono_os_cond_init (mono_cond_t *cond) { -- 2.7.4