[threading] Make thread management coop suspend aware.
authorRodrigo Kumpera <kumpera@gmail.com>
Sun, 29 Mar 2015 00:46:42 +0000 (20:46 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Sun, 29 Mar 2015 16:11:03 +0000 (12:11 -0400)
mono/metadata/threads.c

index c3cb09a71396404adc2e43953d381cd96d7f51b4..6af48dbd3186d360e902d68c9d782857d07be704 100644 (file)
@@ -772,8 +772,12 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
         * starts
         */
        create_flags = CREATE_SUSPENDED;
+
+       MONO_PREPARE_BLOCKING
        thread_handle = mono_threads_create_thread ((LPTHREAD_START_ROUTINE)start_wrapper, start_info,
                                                                                                stack_size, create_flags, &tid);
+       MONO_FINISH_BLOCKING
+
        if (thread_handle == NULL) {
                /* The thread couldn't be created, so throw an exception */
                mono_threads_lock ();
@@ -804,7 +808,9 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
        if (!handle_store (thread, FALSE))
                return FALSE;
 
+       MONO_PREPARE_BLOCKING
        mono_thread_info_resume (tid);
+       MONO_FINISH_BLOCKING
 
        if (internal->start_notify) {
                /*
@@ -815,7 +821,10 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
                 */
                THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") waiting for thread %p (%"G_GSIZE_FORMAT") to start", __func__, GetCurrentThreadId (), internal, (gsize)internal->tid));
 
+               MONO_PREPARE_BLOCKING
                WaitForSingleObjectEx (internal->start_notify, INFINITE, FALSE);
+               MONO_FINISH_BLOCKING
+
                CloseHandle (internal->start_notify);
                internal->start_notify = NULL;
        }
@@ -1129,7 +1138,9 @@ ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms)
        while (TRUE) {
                mono_thread_set_state (thread, ThreadState_WaitSleepJoin);
        
+               MONO_PREPARE_BLOCKING
                res = SleepEx(ms,TRUE);
+               MONO_FINISH_BLOCKING
        
                mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
 
@@ -1344,7 +1355,9 @@ ves_icall_System_Threading_Thread_Join_internal(MonoInternalThread *this,
        
        mono_thread_set_state (cur_thread, ThreadState_WaitSleepJoin);
 
+       MONO_PREPARE_BLOCKING
        ret=WaitForSingleObjectEx (thread, ms, TRUE);
+       MONO_FINISH_BLOCKING
 
        mono_thread_clr_state (cur_thread, ThreadState_WaitSleepJoin);
        
@@ -1370,10 +1383,12 @@ mono_wait_uninterrupted (MonoInternalThread *thread, gboolean multiple, guint32
 
        start = (ms == -1) ? 0 : mono_100ns_ticks ();
        do {
-               if (multiple)
+               MONO_PREPARE_BLOCKING
+                       if (multiple)
                        ret = WaitForMultipleObjectsEx (numhandles, handles, waitall, wait, alertable);
                else
                        ret = WaitForSingleObjectEx (handles [0], ms, alertable);
+               MONO_FINISH_BLOCKING
 
                if (ret != WAIT_IO_COMPLETION)
                        break;
@@ -1534,7 +1549,9 @@ ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (HANDLE toSignal, H
 
        mono_thread_set_state (thread, ThreadState_WaitSleepJoin);
        
+       MONO_PREPARE_BLOCKING
        ret = SignalObjectAndWait (toSignal, toWait, ms, TRUE);
+       MONO_FINISH_BLOCKING
        
        mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);