From 207b1fa616910e24ff77f4bfd42d1b623b4ca535 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 16 Apr 2015 19:01:13 -0400 Subject: [PATCH] [threading] Add a global variable that is set while a global suspend is hapening. This global var is meant to be used by JIT'd code to efficiently implement polling. --- mono/utils/mono-threads-coop.c | 13 +++++++++++++ mono/utils/mono-threads-coop.h | 3 +++ mono/utils/mono-threads-posix.c | 10 ++++++++++ mono/utils/mono-threads-windows.c | 10 ++++++++++ mono/utils/mono-threads.c | 2 ++ mono/utils/mono-threads.h | 3 +++ 6 files changed, 41 insertions(+) diff --git a/mono/utils/mono-threads-coop.c b/mono/utils/mono-threads-coop.c index f19021b5a56..b44719109ff 100644 --- a/mono/utils/mono-threads-coop.c +++ b/mono/utils/mono-threads-coop.c @@ -19,6 +19,7 @@ #ifdef USE_COOP_BACKEND +volatile size_t mono_polling_required; void mono_threads_state_poll (void) @@ -249,5 +250,17 @@ mono_threads_platform_register (MonoThreadInfo *info) //See the above for what's wrong here. } +void +mono_threads_core_begin_global_suspend (void) +{ + mono_polling_required = 1; +} + +void +mono_threads_core_end_global_suspend (void) +{ + mono_polling_required = 0; +} + #endif \ No newline at end of file diff --git a/mono/utils/mono-threads-coop.h b/mono/utils/mono-threads-coop.h index 8626288f353..6eca0266dcf 100644 --- a/mono/utils/mono-threads-coop.h +++ b/mono/utils/mono-threads-coop.h @@ -58,6 +58,9 @@ void mono_threads_reset_blocking_end (void* cookie); void* mono_threads_try_prepare_blocking (void); void mono_threads_finish_try_blocking (void* cookie); +/* JIT specific interface */ +extern volatile size_t mono_polling_required ; + #else #define MONO_SUSPEND_CHECK do { } while (0); diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 94f58cdc58e..19fd8b7c12e 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -635,6 +635,16 @@ mono_threads_platform_free (MonoThreadInfo *info) { } +void +mono_threads_core_begin_global_suspend (void) +{ +} + +void +mono_threads_core_end_global_suspend (void) +{ +} + #endif /*defined (USE_POSIX_BACKEND)*/ #endif diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c index af7bee62097..b5008b4859e 100755 --- a/mono/utils/mono-threads-windows.c +++ b/mono/utils/mono-threads-windows.c @@ -407,4 +407,14 @@ mono_threads_core_clear_interruption (void) { } +void +mono_threads_core_begin_global_suspend (void) +{ +} + +void +mono_threads_core_end_global_suspend (void) +{ +} + #endif diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c index 814a8e45754..bb9acf9103c 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -123,6 +123,7 @@ mono_threads_begin_global_suspend (void) { g_assert (pending_suspends == 0); THREADS_SUSPEND_DEBUG ("------ BEGIN GLOBAL OP sp %d rp %d wd %d po %d\n", suspend_posts, resume_posts, waits_done, pending_ops); + mono_threads_core_begin_global_suspend (); } void @@ -130,6 +131,7 @@ mono_threads_end_global_suspend (void) { g_assert (pending_suspends == 0); THREADS_SUSPEND_DEBUG ("------ END GLOBAL OP sp %d rp %d wd %d po %d\n", suspend_posts, resume_posts, waits_done, pending_ops); + mono_threads_core_end_global_suspend (); } static void diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index a9a7b914baa..f04543cb4cf 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -483,6 +483,9 @@ HANDLE mono_threads_core_open_handle (void); HANDLE mono_threads_core_open_thread_handle (HANDLE handle, MonoNativeThreadId tid); void mono_threads_core_set_name (MonoNativeThreadId tid, const char *name); +void mono_threads_core_begin_global_suspend (void); +void mono_threads_core_end_global_suspend (void); + /* Internal API between mono-threads and its backends. */ /* Backend functions - a backend must implement all of the following */ -- 2.11.4.GIT