Merge pull request #4381 from BrzVlad/feature-generational-hash
[mono.git] / mono / metadata / threadpool-io.c
index c5429ffeef16c3faeb4a69b9e54a0001477eaaf5..4f4fa7b1559c202ec6d0ef11435e43504759831c 100644 (file)
@@ -306,6 +306,12 @@ wait_callback (gint fd, gint events, gpointer user_data)
        }
 }
 
+static void
+selector_thread_interrupt (gpointer unused)
+{
+       selector_thread_wakeup ();
+}
+
 static gsize WINAPI
 selector_thread (gpointer data)
 {
@@ -321,9 +327,13 @@ selector_thread (gpointer data)
 
        states = mono_g_hash_table_new_type (g_direct_hash, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool states table");
 
-       for (;;) {
+       while (!mono_runtime_is_shutting_down ()) {
                gint i, j;
                gint res;
+               gboolean interrupted = FALSE;
+
+               if (mono_thread_interruption_checkpoint ())
+                       continue;
 
                mono_coop_mutex_lock (&threadpool_io->updates_lock);
 
@@ -422,10 +432,15 @@ selector_thread (gpointer data)
 
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_THREADPOOL, "io threadpool: wai");
 
-               res = threadpool_io->backend.event_wait (wait_callback, states);
+               mono_thread_info_install_interrupt (selector_thread_interrupt, NULL, &interrupted);
+               if (interrupted)
+                       continue;
 
-               if (res == -1 || mono_runtime_is_shutting_down ())
+               res = threadpool_io->backend.event_wait (wait_callback, states);
+               if (res == -1)
                        break;
+
+               mono_thread_info_uninstall_interrupt (&interrupted);
        }
 
        mono_g_hash_table_destroy (states);
@@ -548,13 +563,7 @@ initialize (void)
 static void
 cleanup (void)
 {
-       /* we make the assumption along the code that we are
-        * cleaning up only if the runtime is shutting down */
-       g_assert (mono_runtime_is_shutting_down ());
-
-       selector_thread_wakeup ();
-       while (io_selector_running)
-               mono_thread_info_usleep (1000);
+       // FIXME destroy everything
 }
 
 void