Merge pull request #1991 from esdrubal/seq_test_fix
[mono.git] / mono / metadata / threadpool-ms.c
index b9a5a8d07601abde9c9d6d27f8909a1c8f27b278..d5e388d1e28186ec210c79788ea9f43bda0361e2 100644 (file)
@@ -315,10 +315,14 @@ cleanup (void)
         * cleaning up only if the runtime is shutting down */
        g_assert (mono_runtime_is_shutting_down ());
 
+       MONO_PREPARE_BLOCKING;
        while (monitor_status != MONITOR_STATUS_NOT_RUNNING)
                g_usleep (1000);
+       MONO_FINISH_BLOCKING;
 
+       MONO_PREPARE_BLOCKING;
        mono_mutex_lock (&threadpool->active_threads_lock);
+       MONO_FINISH_BLOCKING;
 
        /* stop all threadpool->working_threads */
        for (i = 0; i < threadpool->working_threads->len; ++i)
@@ -525,6 +529,8 @@ worker_try_unpark (void)
 
        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker", GetCurrentThreadId ());
 
+       MONO_PREPARE_BLOCKING;
+
        mono_mutex_lock (&threadpool->active_threads_lock);
        len = threadpool->parked_threads->len;
        if (len > 0) {
@@ -534,6 +540,8 @@ worker_try_unpark (void)
        }
        mono_mutex_unlock (&threadpool->active_threads_lock);
 
+       MONO_FINISH_BLOCKING;
+
        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] try unpark worker, success? %s", GetCurrentThreadId (), res ? "yes" : "no");
 
        return res;
@@ -571,9 +579,11 @@ worker_thread (gpointer data)
 
        mono_thread_set_name_internal (thread, mono_string_new (mono_domain_get (), "Threadpool worker"), FALSE);
 
+       MONO_PREPARE_BLOCKING;
        mono_mutex_lock (&threadpool->active_threads_lock);
        g_ptr_array_add (threadpool->working_threads, thread);
        mono_mutex_unlock (&threadpool->active_threads_lock);
+       MONO_FINISH_BLOCKING;
 
        previous_tpdomain = NULL;
 
@@ -657,9 +667,11 @@ worker_thread (gpointer data)
 
        mono_mutex_unlock (&threadpool->domains_lock);
 
+       MONO_PREPARE_BLOCKING;
        mono_mutex_lock (&threadpool->active_threads_lock);
        g_ptr_array_remove_fast (threadpool->working_threads, thread);
        mono_mutex_unlock (&threadpool->active_threads_lock);
+       MONO_FINISH_BLOCKING;
 
        COUNTER_ATOMIC (counter, {
                counter._.working--;
@@ -852,6 +864,7 @@ monitor_thread (void)
                if (mono_runtime_is_shutting_down () || !domain_any_has_request ())
                        continue;
 
+               MONO_PREPARE_BLOCKING;
                mono_mutex_lock (&threadpool->active_threads_lock);
                for (i = 0; i < threadpool->working_threads->len; ++i) {
                        thread = g_ptr_array_index (threadpool->working_threads, i);
@@ -861,6 +874,7 @@ monitor_thread (void)
                        }
                }
                mono_mutex_unlock (&threadpool->active_threads_lock);
+               MONO_FINISH_BLOCKING;
 
                if (all_waitsleepjoin) {
                        ThreadPoolCounter counter;