Merge pull request #2530 from lambdageek/monoerror-mono_string_new
[mono.git] / mono / utils / mono-threads-coop.c
index edfb11d6c028b7aea1737d98cfa8d0c13173af19..3b11148aafe3af5d8c7ff2d93368bb3033da1e10 100644 (file)
@@ -15,7 +15,6 @@
 #endif
 
 #include <mono/utils/mono-compiler.h>
-#include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-tls.h>
 #include <mono/utils/hazard-pointer.h>
@@ -25,6 +24,7 @@
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-counters.h>
 #include <mono/utils/mono-threads-coop.h>
+#include <mono/utils/mono-threads-api.h>
 
 #ifdef TARGET_OSX
 #include <mono/utils/mach-support.h>
@@ -158,7 +158,7 @@ mono_threads_finish_blocking (void *cookie, void* stackdata)
        if (!mono_threads_is_coop_enabled ())
                return;
 
-       info = cookie;
+       info = (MonoThreadInfo *)cookie;
        if (!info)
                return;
 
@@ -228,7 +228,7 @@ mono_threads_reset_blocking_end (void *cookie, void* stackdata)
        if (!mono_threads_is_coop_enabled ())
                return;
 
-       info = cookie;
+       info = (MonoThreadInfo *)cookie;
        if (!info)
                return;
 
@@ -236,49 +236,6 @@ mono_threads_reset_blocking_end (void *cookie, void* stackdata)
        mono_threads_prepare_blocking (stackdata);
 }
 
-void*
-mono_threads_try_prepare_blocking (void* stackdata)
-{
-       MonoThreadInfo *info;
-
-       if (!mono_threads_is_coop_enabled ())
-               return NULL;
-
-       ++coop_try_blocking_count;
-
-       info = mono_thread_info_current_unchecked ();
-       /* If the thread is not attached, it doesn't make sense prepare for suspend. */
-       if (!info || !mono_thread_info_is_live (info) || mono_thread_info_current_state (info) == STATE_BLOCKING) {
-               THREADS_SUSPEND_DEBUG ("PREPARE-TRY-BLOCKING failed %p\n", mono_thread_info_get_tid (info));
-               return NULL;
-       }
-
-       copy_stack_data (info, stackdata);
-
-retry:
-       ++coop_save_count;
-       mono_threads_get_runtime_callbacks ()->thread_state_init (&info->thread_saved_state [SELF_SUSPEND_STATE_INDEX]);
-
-       switch (mono_threads_transition_do_blocking (info)) {
-       case DoBlockingContinue:
-               break;
-       case DoBlockingPollAndRetry:
-               mono_threads_state_poll ();
-               goto retry;
-       }
-
-       return info;
-}
-
-void
-mono_threads_finish_try_blocking (void* cookie, void* stackdata)
-{
-       if (!mono_threads_is_coop_enabled ())
-               return;
-
-       mono_threads_finish_blocking (cookie, stackdata);
-}
-
 void
 mono_threads_init_coop (void)
 {
@@ -307,8 +264,8 @@ mono_threads_coop_end_global_suspend (void)
                mono_polling_required = 0;
 }
 
-void*
-mono_threads_enter_gc_unsafe_region (void* stackdata)
+gpointer
+mono_threads_enter_gc_unsafe_region (gpointer* stackdata)
 {
        if (!mono_threads_is_coop_enabled ())
                return NULL;
@@ -317,10 +274,40 @@ mono_threads_enter_gc_unsafe_region (void* stackdata)
 }
 
 void
-mono_threads_exit_gc_unsafe_region (void *regions_cookie, void* stackdata)
+mono_threads_exit_gc_unsafe_region (gpointer cookie, gpointer* stackdata)
+{
+       if (!mono_threads_is_coop_enabled ())
+               return;
+
+       mono_threads_reset_blocking_end (cookie, stackdata);
+}
+
+void
+mono_threads_assert_gc_unsafe_region (void)
+{
+       MONO_REQ_GC_UNSAFE_MODE;
+}
+
+gpointer
+mono_threads_enter_gc_safe_region (gpointer *stackdata)
+{
+       if (!mono_threads_is_coop_enabled ())
+               return NULL;
+
+       return mono_threads_prepare_blocking (stackdata);
+}
+
+void
+mono_threads_exit_gc_safe_region (gpointer cookie, gpointer *stackdata)
 {
        if (!mono_threads_is_coop_enabled ())
                return;
 
-       mono_threads_reset_blocking_end (regions_cookie, stackdata);
+       mono_threads_finish_blocking (cookie, stackdata);
+}
+
+void
+mono_threads_assert_gc_safe_region (void)
+{
+       MONO_REQ_GC_SAFE_MODE;
 }