[threadpool] Make sure we check if the runtime is shutting down in case of interruption
authorLudovic Henry <ludovic@xamarin.com>
Wed, 8 Feb 2017 19:32:00 +0000 (14:32 -0500)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 16 Feb 2017 20:36:44 +0000 (15:36 -0500)
mono/metadata/threadpool.c

index 455d616a767ac5655ca221cdb0c53ff8d579a38e..7f7c31f0631ab5d5bc279212b98d939f369ce43b 100644 (file)
@@ -309,11 +309,11 @@ static ThreadPoolDomain *
 tpdomain_get_next (ThreadPoolDomain *current)
 {
        ThreadPoolDomain *tpdomain = NULL;
-       guint len;
+       gint len;
 
        len = threadpool.domains->len;
        if (len > 0) {
-               guint i, current_idx = -1;
+               gint i, current_idx = -1;
                if (current) {
                        for (i = 0; i < len; ++i) {
                                if (current == g_ptr_array_index (threadpool.domains, i)) {
@@ -321,7 +321,6 @@ tpdomain_get_next (ThreadPoolDomain *current)
                                        break;
                                }
                        }
-                       g_assert (current_idx != (guint)-1);
                }
                for (i = current_idx + 1; i < len + current_idx + 1; ++i) {
                        ThreadPoolDomain *tmp = (ThreadPoolDomain *)g_ptr_array_index (threadpool.domains, i % len);
@@ -388,9 +387,12 @@ worker_callback (gpointer unused)
        while (!mono_runtime_is_shutting_down ()) {
                gboolean retire = FALSE;
 
-               if ((thread->state & (ThreadState_AbortRequested | ThreadState_SuspendRequested)) != 0) {
+               if (thread->state & (ThreadState_AbortRequested | ThreadState_SuspendRequested)) {
                        domains_unlock ();
-                       mono_thread_interruption_checkpoint ();
+                       if (mono_thread_interruption_checkpoint ()) {
+                               domains_lock ();
+                               continue;
+                       }
                        domains_lock ();
                }