-/*
- * threadpool-io.c: Microsoft IO threadpool runtime support
+/**
+ * \file
+ * Microsoft IO threadpool runtime support
*
* Author:
* Ludovic Henry (ludovic.henry@xamarin.com)
MonoError error;
MonoGHashTable *states;
- io_selector_running = TRUE;
-
if (mono_runtime_is_shutting_down ()) {
io_selector_running = FALSE;
return 0;
mono_g_hash_table_destroy (states);
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
+
io_selector_running = FALSE;
+ mono_coop_cond_broadcast (&threadpool_io->updates_cond);
+
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
return 0;
}
threadpool_io->updates_size = 0;
threadpool_io->backend = backend_poll;
- if (g_getenv ("MONO_ENABLE_AIO") != NULL) {
+ if (g_hasenv ("MONO_ENABLE_AIO")) {
#if defined(HAVE_EPOLL)
threadpool_io->backend = backend_epoll;
#elif defined(HAVE_KQUEUE)
if (!threadpool_io->backend.init (threadpool_io->wakeup_pipes [0]))
g_error ("initialize: backend->init () failed");
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
+
+ io_selector_running = TRUE;
+
MonoError error;
- if (!mono_thread_create_internal (mono_get_root_domain (), selector_thread, NULL, TRUE, SMALL_STACK, &error))
+ if (!mono_thread_create_internal (mono_get_root_domain (), selector_thread, NULL, MONO_THREAD_CREATE_FLAGS_THREADPOOL | MONO_THREAD_CREATE_FLAGS_SMALL_STACK, &error))
g_error ("initialize: mono_thread_create_internal () failed due to %s", mono_error_get_message (&error));
+
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
}
static void
mono_coop_mutex_lock (&threadpool_io->updates_lock);
+ if (!io_selector_running) {
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
+ return;
+ }
+
update = update_get_new ();
update->type = UPDATE_ADD;
update->data.add.fd = GPOINTER_TO_INT (handle);
mono_coop_mutex_lock (&threadpool_io->updates_lock);
+ if (!io_selector_running) {
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
+ return;
+ }
+
update = update_get_new ();
update->type = UPDATE_REMOVE_SOCKET;
update->data.add.fd = fd;
mono_coop_mutex_lock (&threadpool_io->updates_lock);
+ if (!io_selector_running) {
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
+ return;
+ }
+
update = update_get_new ();
update->type = UPDATE_REMOVE_DOMAIN;
update->data.remove_domain.domain = domain;