[threading] Reorganize code to work with the coop backend.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 2 Feb 2015 16:04:37 +0000 (11:04 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 25 Mar 2015 17:49:38 +0000 (13:49 -0400)
This splits the native backend from core functionality it needs to provide. For example,on posix, we want to
use the pthread_create code regardless of the backend enabled.

mono/utils/mono-threads-mach.c
mono/utils/mono-threads-posix.c
mono/utils/mono-threads-windows.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h

index f38927bb87087d09e8c3dde54400295acdca76e2..14db1cc9550ab00c2e32ffda88c5f60ee64ec32d 100644 (file)
@@ -165,34 +165,6 @@ mono_threads_platform_free (MonoThreadInfo *info)
        mach_port_deallocate (current_task (), info->native_handle);
 }
 
-MonoNativeThreadId
-mono_native_thread_id_get (void)
-{
-       return pthread_self ();
-}
-
-gboolean
-mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
-{
-       return pthread_equal (id1, id2);
-}
-
-/*
- * mono_native_thread_create:
- *
- *   Low level thread creation function without any GC wrappers.
- */
-gboolean
-mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
-{
-       return pthread_create (tid, NULL, func, arg) == 0;
-}
-
-void
-mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
-{
-       /* pthread_setnmae_np() on Mac is not documented and doesn't receive thread id. */
-}
 #endif /* USE_MACH_BACKEND */
 
 #ifdef __MACH__
index 0afc71191c31fed3ab3861fb15184aba8c8c7f54..303f2529aeeed6dbda934b097c17647261792444 100644 (file)
@@ -287,10 +287,49 @@ mono_threads_pthread_kill (MonoThreadInfo *info, int signum)
 #else
        return pthread_kill (mono_thread_info_get_tid (info), signum);
 #endif
+}
+
+MonoNativeThreadId
+mono_native_thread_id_get (void)
+{
+       return pthread_self ();
+}
 
+gboolean
+mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
+{
+       return pthread_equal (id1, id2);
 }
 
-#if defined (USE_POSIX_BACKEND)
+/*
+ * mono_native_thread_create:
+ *
+ *   Low level thread creation function without any GC wrappers.
+ */
+gboolean
+mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
+{
+       return pthread_create (tid, NULL, func, arg) == 0;
+}
+
+void
+mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
+{
+#if defined (HAVE_PTHREAD_SETNAME_NP) && !defined (__MACH__)
+       if (!name) {
+               pthread_setname_np (tid, "");
+       } else {
+               char n [16];
+
+               strncpy (n, name, 16);
+               n [15] = '\0';
+               pthread_setname_np (tid, n);
+       }
+#endif
+}
+
+
+#if defined (USE_POSIX_BACKEND) && !defined (USE_COOP_GC)
 
 static int suspend_signal_num;
 static int restart_signal_num;
@@ -593,45 +632,6 @@ mono_threads_platform_free (MonoThreadInfo *info)
 {
 }
 
-MonoNativeThreadId
-mono_native_thread_id_get (void)
-{
-       return pthread_self ();
-}
-
-gboolean
-mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
-{
-       return pthread_equal (id1, id2);
-}
-
-/*
- * mono_native_thread_create:
- *
- *   Low level thread creation function without any GC wrappers.
- */
-gboolean
-mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
-{
-       return pthread_create (tid, NULL, func, arg) == 0;
-}
-
-void
-mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
-{
-#if defined (HAVE_PTHREAD_SETNAME_NP) && !defined (__MACH__)
-       if (!name) {
-               pthread_setname_np (tid, "");
-       } else {
-               char n [16];
-
-               strncpy (n, name, 16);
-               n [15] = '\0';
-               pthread_setname_np (tid, n);
-       }
-#endif
-}
-
 #endif /*defined (USE_POSIX_BACKEND)*/
 
 #endif
index 190720b94d03662d6e9849feae8be1a5833a5f62..28f8534c7d53700b294dbdcaf25b29f15ecc7282 100755 (executable)
@@ -7,11 +7,10 @@
  * (C) 2011 Novell, Inc
  */
 
-#include "config.h"
+#include <mono/utils/mono-threads.h>
 
-#if defined(HOST_WIN32)
+#if defined(USE_WINDOWS_BACKEND)
 
-#include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-compiler.h>
 #include <limits.h>
 
index 1e2909dd02c3a6c6a62652e32dca3d6c6f43b4ea..d1a9c5ab0bb048d66bdffffc30474490bb96d2b9 100644 (file)
@@ -538,7 +538,7 @@ mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
 #endif
        g_assert (res);
 
-       unified_suspend_enabled = g_getenv ("MONO_ENABLE_UNIFIED_SUSPEND") != NULL;
+       unified_suspend_enabled = g_getenv ("MONO_ENABLE_UNIFIED_SUSPEND") != NULL || MONO_THREADS_PLATFORM_REQUIRES_UNIFIED_SUSPEND;
 
        MONO_SEM_INIT (&global_suspend_semaphore, 1);
        MONO_SEM_INIT (&suspend_semaphore, 0);
index 37447f72b24fed7228178d9b4ab0dcb2653f2515..c0b92219844d9478869d4ef5a917b8229dfa0b44 100644 (file)
@@ -119,14 +119,25 @@ and reduce the number of casts drastically.
 /* If this is defined, use the signals backed on Mach. Debug only as signals can't be made usable on OSX. */
 // #define USE_SIGNALS_ON_MACH
 
-#if defined (_POSIX_VERSION) || defined (__native_client__)
+
+#if defined (USE_COOP_GC)
+#define USE_COOP_BACKEND
+#define MONO_THREADS_PLATFORM_REQUIRES_UNIFIED_SUSPEND 1
+
+#elif defined (_POSIX_VERSION) || defined (__native_client__)
+#define MONO_THREADS_PLATFORM_REQUIRES_UNIFIED_SUSPEND 0
+
 #if defined (__MACH__) && !defined (USE_SIGNALS_ON_MACH)
 #define USE_MACH_BACKEND
 #else
 #define USE_POSIX_BACKEND
 #endif
-#endif
 
+#elif HOST_WIN32
+#define MONO_THREADS_PLATFORM_REQUIRES_UNIFIED_SUSPEND 0
+#define USE_WINDOWS_BACKEND
+
+#endif
 
 enum {
        STATE_STARTING                          = 0x00,