[coop] mono_thread_info_suspend_lock is a non-leaf lock so we need to checkpoint...
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 17 Aug 2015 23:52:15 +0000 (19:52 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 18 Aug 2015 05:23:45 +0000 (01:23 -0400)
mono_thread_info_suspend_lock is, on first sight, a leaf lock. But since it can suspend a thread that is holding other locks,
it has the same global effect of one.

mono/utils/mono-threads.c

index 671bcd4ea8623592677d80a14710211f138d9bd0..4b2bcdc6937683efc045e2e05bec08cb70942974 100644 (file)
@@ -357,14 +357,7 @@ unregister_thread (void *arg)
        if (threads_callbacks.thread_detach)
                threads_callbacks.thread_detach (info);
 
-       /*
-       Since the thread info lock is taken from within blocking sections, we can't check from there, so it must be done here.
-       This ensures that we won't lose any suspend requests as a suspend initiator must hold the lock.
-       Once we're holding the suspend lock, no threads can suspend us and once we unregister, no thread can find us. 
-       */
-       MONO_PREPARE_BLOCKING;
        mono_thread_info_suspend_lock ();
-       MONO_FINISH_BLOCKING;
 
        /*
        Now perform the callback that must be done under locks.
@@ -885,9 +878,7 @@ mono_thread_info_safe_suspend_and_run (MonoNativeThreadId id, gboolean interrupt
        g_assert (id != mono_native_thread_id_get ());
 
        /* This can block during stw */
-       MONO_PREPARE_BLOCKING;
        mono_thread_info_suspend_lock ();
-       MONO_FINISH_BLOCKING;
        mono_threads_begin_global_suspend ();
 
        info = suspend_sync_nolock (id, interrupt_kernel);
@@ -971,7 +962,9 @@ STW to make sure no unsafe pending suspend is in progress.
 void
 mono_thread_info_suspend_lock (void)
 {
+       MONO_TRY_BLOCKING;
        MONO_SEM_WAIT_UNITERRUPTIBLE (&global_suspend_semaphore);
+       MONO_FINISH_TRY_BLOCKING;
 }
 
 void