From d78ba0e327ec1c16b5820b05f4deac6389eeff69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 14 Sep 2016 14:59:42 +0200 Subject: [PATCH] [utils/threads] Add and export a mono_native_thread_join () function. --- mono/metadata/threads.c | 4 ++-- mono/mini/mini-posix.c | 2 +- mono/utils/mono-threads-posix.c | 8 ++++++++ mono/utils/mono-threads-windows.c | 15 +++++++++++++++ mono/utils/mono-threads.h | 3 +++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 2f19acf04e4..0b8aa7c4fb9 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -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 } diff --git a/mono/mini/mini-posix.c b/mono/mini/mini-posix.c index f8a02816291..bdd3149c25b 100644 --- a/mono/mini/mini-posix.c +++ b/mono/mini/mini-posix.c @@ -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 diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 9e6ebe712c2..7d656132b59 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -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) { diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c index 7beb557fc70..5d6774ed4d7 100644 --- a/mono/utils/mono-threads-windows.c +++ b/mono/utils/mono-threads-windows.c @@ -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) diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index a6798a19e61..72f90e38157 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -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); -- 2.11.4.GIT