[coop] Remove MONO_TRY_BLOCKING
authorLudovic Henry <ludovic@xamarin.com>
Wed, 18 Nov 2015 15:19:54 +0000 (15:19 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Tue, 24 Nov 2015 18:24:40 +0000 (13:24 -0500)
Switching to blocking should only be done when actually blocking (ex: mutex
lock, sem wait, cond wait, blocking syscalls), and not around a whole
section. This means that blocking can only be a leaf state, and we
should not switch from blocking to blocking mode again.

mono/metadata/object.c
mono/metadata/reflection.c
mono/mini/debugger-agent.c
mono/utils/mono-threads-coop.c
mono/utils/mono-threads-coop.h

index ef7d619a717d5299198b56a83bd18e6cc56ffaef..7d2323d29a239029ef7e8a01bccab57274bbeadf 100644 (file)
@@ -2950,10 +2950,10 @@ mono_method_get_unmanaged_thunk (MonoMethod *method)
 
        gpointer res;
 
-       MONO_PREPARE_RESET_BLOCKING
+       MONO_PREPARE_RESET_BLOCKING;
        method = mono_marshal_get_thunk_invoke_wrapper (method);
        res = mono_compile_method (method);
-       MONO_FINISH_RESET_BLOCKING
+       MONO_FINISH_RESET_BLOCKING;
 
        return res;
 }
index 3d34adb29f1e17c9ab403fde6200c5a422f820d2..a6874280ae0781d657c50d95cad05f9a5a3892bd 100644 (file)
@@ -224,9 +224,9 @@ mono_reflection_init (void)
 static inline void
 dynamic_image_lock (MonoDynamicImage *image)
 {
-       MONO_TRY_BLOCKING;
+       MONO_PREPARE_BLOCKING;
        mono_image_lock ((MonoImage*)image);
-       MONO_FINISH_TRY_BLOCKING;
+       MONO_FINISH_BLOCKING;
 }
 
 static inline void
index 702cd96f58cf01992639e3eaebd8171f6460132e..7934aba84712cdf1658d5e2749f843315e37529e 100644 (file)
@@ -1531,18 +1531,18 @@ transport_handshake (void)
        /* Write handshake message */
        sprintf (handshake_msg, "DWP-Handshake");
        /* Must use try blocking as this can nest into code that runs blocking */
-       MONO_TRY_BLOCKING;
+       MONO_PREPARE_BLOCKING;
        do {
                res = transport_send (handshake_msg, strlen (handshake_msg));
        } while (res == -1 && get_last_sock_error () == MONO_EINTR);
-       MONO_FINISH_TRY_BLOCKING;
+       MONO_FINISH_BLOCKING;
 
        g_assert (res != -1);
 
        /* Read answer */
-       MONO_TRY_BLOCKING;
+       MONO_PREPARE_BLOCKING;
        res = transport_recv (buf, strlen (handshake_msg));
-       MONO_FINISH_TRY_BLOCKING;
+       MONO_FINISH_BLOCKING;
        if ((res != strlen (handshake_msg)) || (memcmp (buf, handshake_msg, strlen (handshake_msg)) != 0)) {
                fprintf (stderr, "debugger-agent: DWP handshake failed.\n");
                return FALSE;
index 11a7bdd0ebb12541593eda360377e9ab9bc3e904..d58f3ad507e4ef6a17a4397afbea49be5ebb2ef5 100644 (file)
@@ -235,49 +235,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)
 {
index fa928672400754d15963d1f61fcfbcd588e159d5..4e24389489a65aa9f8891e0edafa4965376b99ac 100644 (file)
@@ -42,9 +42,6 @@ void mono_threads_finish_blocking (void* cookie, void* stackdata);
 void* mono_threads_reset_blocking_start (void* stackdata);
 void mono_threads_reset_blocking_end (void* cookie, void* stackdata);
 
-void* mono_threads_try_prepare_blocking (void* stackdata);
-void mono_threads_finish_try_blocking (void* cookie, void* stackdata);
-
 static inline void
 mono_threads_safepoint (void)
 {
@@ -53,30 +50,21 @@ mono_threads_safepoint (void)
 }
 
 #define MONO_PREPARE_BLOCKING  \
-{      \
-       void *__dummy;  \
-       void *__blocking_cookie = mono_threads_prepare_blocking (&__dummy);
+       do {    \
+               void *__dummy;  \
+               void *__blocking_cookie = mono_threads_prepare_blocking (&__dummy)
 
 #define MONO_FINISH_BLOCKING \
-       mono_threads_finish_blocking (__blocking_cookie, &__dummy);     \
-}
+               mono_threads_finish_blocking (__blocking_cookie, &__dummy);     \
+       } while (0)
 
 #define MONO_PREPARE_RESET_BLOCKING    \
-{      \
-       void *__dummy;  \
-       void *__reset_cookie = mono_threads_reset_blocking_start (&__dummy);
+       do {    \
+               void *__dummy;  \
+               void *__reset_cookie = mono_threads_reset_blocking_start (&__dummy)
 
 #define MONO_FINISH_RESET_BLOCKING \
-       mono_threads_reset_blocking_end (__reset_cookie, &__dummy);     \
-}
-
-#define MONO_TRY_BLOCKING      \
-{      \
-       void *__dummy;  \
-       void *__try_block_cookie = mono_threads_try_prepare_blocking (&__dummy);
-
-#define MONO_FINISH_TRY_BLOCKING \
-       mono_threads_finish_try_blocking (__try_block_cookie, &__dummy);        \
-}
+               mono_threads_reset_blocking_end (__reset_cookie, &__dummy);     \
+       } while (0)
 
 #endif