[utils/threads] Add and export a mono_native_thread_join () function.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Wed, 14 Sep 2016 12:59:42 +0000 (14:59 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sun, 2 Oct 2016 16:55:09 +0000 (18:55 +0200)
mono/metadata/threads.c
mono/mini/mini-posix.c
mono/utils/mono-threads-posix.c
mono/utils/mono-threads-windows.c
mono/utils/mono-threads.h

index 2f19acf04e4453b0aafdcb21c758669543e3a86f..0b8aa7c4fb9a8f3a81632bd188c153adab92f204 100644 (file)
@@ -4921,7 +4921,7 @@ mono_threads_join_threads (void)
                        if (thread != pthread_self ()) {
                                MONO_ENTER_GC_SAFE;
                                /* This shouldn't block */
-                               pthread_join (thread, NULL);
+                               mono_native_thread_join (thread);
                                MONO_EXIT_GC_SAFE;
                        }
                } else {
@@ -4957,7 +4957,7 @@ mono_thread_join (gpointer tid)
                return;
        thread = (pthread_t)tid;
        MONO_ENTER_GC_SAFE;
-       pthread_join (thread, NULL);
+       mono_native_thread_join (thread);
        MONO_EXIT_GC_SAFE;
 #endif
 }
index f8a02816291f4b52fe1427dd165c3dd060b46add..bdd3149c25bf25581ed0449fa8630a8eec6f02b0 100644 (file)
@@ -783,7 +783,7 @@ mono_runtime_shutdown_stat_profiler (void)
        }
 #endif
 
-       pthread_join (sampling_thread, NULL);
+       mono_native_thread_join (sampling_thread);
 
        /*
         * We can't safely remove the signal handler because we have no guarantee
index 9e6ebe712c2c446ba607190f6d4fb8d14c477c62..7d656132b5908b35b491f4c439eefa66c83cd243 100644 (file)
@@ -288,6 +288,14 @@ mono_native_thread_set_name (MonoNativeThreadId tid, const char *name)
 #endif
 }
 
+gboolean
+mono_native_thread_join (MonoNativeThreadId tid)
+{
+       void *res;
+
+       return !pthread_join (tid, &res);
+}
+
 void
 mono_threads_platform_set_exited (gpointer handle)
 {
index 7beb557fc70ef3661f0c5b7e0ed7705dd97708b1..5d6774ed4d7ea1c051365f841939c9d407dcec22 100644 (file)
@@ -187,6 +187,21 @@ mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
        return CreateThread (NULL, 0, (func), (arg), 0, (tid)) != NULL;
 }
 
+gboolean
+mono_native_thread_join (MonoNativeThreadId tid)
+{
+       HANDLE handle;
+
+       if (!(handle = OpenThread (THREAD_ALL_ACCESS, TRUE, tid)))
+               return FALSE;
+
+       DWORD res = WaitForSingleObject (handle, INFINITE);
+
+       CloseHandle (handle);
+
+       return res != WAIT_FAILED;
+}
+
 #if HAVE_DECL___READFSDWORD==0
 static MONO_ALWAYS_INLINE unsigned long long
 __readfsdword (unsigned long offset)
index a6798a19e617f8732ee069ff2eee1af998d6f7ef..72f90e38157111c857703ab676bda8cb7ba12162 100644 (file)
@@ -540,6 +540,9 @@ mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
 MONO_API void
 mono_native_thread_set_name (MonoNativeThreadId tid, const char *name);
 
+MONO_API gboolean
+mono_native_thread_join (MonoNativeThreadId tid);
+
 /*Mach specific internals */
 void mono_threads_init_dead_letter (void);
 void mono_threads_install_dead_letter (void);