* Ludovic Henry (ludovic.henry@xamarin.com)
*
* Copyright 2015 Xamarin, Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
ThreadPoolIOUpdate updates [UPDATES_CAPACITY];
gint updates_size;
- mono_mutex_t updates_lock;
- mono_cond_t updates_cond;
+ MonoCoopMutex updates_lock;
+ MonoCoopCond updates_cond;
#if !defined(HOST_WIN32)
gint wakeup_pipes [2];
filter_jobs_for_domain (gpointer key, gpointer value, gpointer user_data)
{
FilterSockaresForDomainData *data;
- MonoMList *list = value, *element;
+ MonoMList *list = (MonoMList *)value, *element;
MonoDomain *domain;
MonoGHashTable *states;
g_assert (user_data);
- data = user_data;
+ data = (FilterSockaresForDomainData *)user_data;
domain = data->domain;
states = data->states;
static void
wait_callback (gint fd, gint events, gpointer user_data)
{
+ MonoError error;
+
if (mono_runtime_is_shutting_down ())
return;
gint operations;
g_assert (user_data);
- states = user_data;
+ states = (MonoGHashTable *)user_data;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_THREADPOOL, "io threadpool: cal fd %3d, events = %2s | %2s | %3s",
fd, (events & EVENT_IN) ? "RD" : "..", (events & EVENT_OUT) ? "WR" : "..", (events & EVENT_ERR) ? "ERR" : "...");
if (list && (events & EVENT_IN) != 0) {
MonoIOSelectorJob *job = get_job_for_event (&list, EVENT_IN);
- if (job)
- mono_threadpool_ms_enqueue_work_item (((MonoObject*) job)->vtable->domain, (MonoObject*) job);
+ if (job) {
+ mono_threadpool_ms_enqueue_work_item (((MonoObject*) job)->vtable->domain, (MonoObject*) job, &error);
+ mono_error_raise_exception (&error); /* FIXME don't raise here */
+ }
+
}
if (list && (events & EVENT_OUT) != 0) {
MonoIOSelectorJob *job = get_job_for_event (&list, EVENT_OUT);
- if (job)
- mono_threadpool_ms_enqueue_work_item (((MonoObject*) job)->vtable->domain, (MonoObject*) job);
+ if (job) {
+ mono_threadpool_ms_enqueue_work_item (((MonoObject*) job)->vtable->domain, (MonoObject*) job, &error);
+ mono_error_raise_exception (&error); /* FIXME don't raise here */
+ }
}
remove_fd = (events & EVENT_ERR) == EVENT_ERR;
static void
selector_thread (gpointer data)
{
+ MonoError error;
MonoGHashTable *states;
io_selector_running = TRUE;
gint i, j;
gint res;
- mono_mutex_lock (&threadpool_io->updates_lock);
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
for (i = 0; i < threadpool_io->updates_size; ++i) {
ThreadPoolIOUpdate *update = &threadpool_io->updates [i];
memset (update, 0, sizeof (ThreadPoolIOUpdate));
}
- for (; list; list = mono_mlist_remove_item (list, list))
- mono_threadpool_ms_enqueue_work_item (mono_object_domain (mono_mlist_get_data (list)), mono_mlist_get_data (list));
+ for (; list; list = mono_mlist_remove_item (list, list)) {
+ mono_threadpool_ms_enqueue_work_item (mono_object_domain (mono_mlist_get_data (list)), mono_mlist_get_data (list), &error);
+ mono_error_raise_exception (&error); /* FIXME don't raise here */
+ }
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_THREADPOOL, "io threadpool: del fd %3d", fd);
threadpool_io->backend.remove_fd (fd);
}
}
- mono_cond_broadcast (&threadpool_io->updates_cond);
+ mono_coop_cond_broadcast (&threadpool_io->updates_cond);
if (threadpool_io->updates_size > 0) {
threadpool_io->updates_size = 0;
memset (&threadpool_io->updates, 0, UPDATES_CAPACITY * sizeof (ThreadPoolIOUpdate));
}
- mono_mutex_unlock (&threadpool_io->updates_lock);
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_THREADPOOL, "io threadpool: wai");
/* we wait for updates to be applied in the selector_thread and we loop
* as long as none are available. if it happends too much, then we need
* to increase UPDATES_CAPACITY */
- mono_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
+ mono_coop_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
}
g_assert (threadpool_io->updates_size < UPDATES_CAPACITY);
threadpool_io = g_new0 (ThreadPoolIO, 1);
g_assert (threadpool_io);
- mono_mutex_init_recursive (&threadpool_io->updates_lock);
- mono_cond_init (&threadpool_io->updates_cond);
- mono_gc_register_root ((void*)&threadpool_io->updates [0], sizeof (threadpool_io->updates), MONO_GC_DESCRIPTOR_NULL, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool updates list");
+ mono_coop_mutex_init (&threadpool_io->updates_lock);
+ mono_coop_cond_init (&threadpool_io->updates_cond);
+ mono_gc_register_root ((char *)&threadpool_io->updates [0], sizeof (threadpool_io->updates), MONO_GC_DESCRIPTOR_NULL, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool updates list");
threadpool_io->updates_size = 0;
selector_thread_wakeup ();
while (io_selector_running)
- g_usleep (1000);
+ mono_thread_info_usleep (1000);
- mono_mutex_destroy (&threadpool_io->updates_lock);
- mono_cond_destroy (&threadpool_io->updates_cond);
+ mono_coop_mutex_destroy (&threadpool_io->updates_lock);
+ mono_coop_cond_destroy (&threadpool_io->updates_cond);
threadpool_io->backend.cleanup ();
mono_lazy_initialize (&io_status, initialize);
- mono_mutex_lock (&threadpool_io->updates_lock);
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
update = update_get_new ();
update->type = UPDATE_ADD;
selector_thread_wakeup ();
- mono_mutex_unlock (&threadpool_io->updates_lock);
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
}
void
if (!mono_lazy_is_initialized (&io_status))
return;
- mono_mutex_lock (&threadpool_io->updates_lock);
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
update = update_get_new ();
update->type = UPDATE_REMOVE_SOCKET;
selector_thread_wakeup ();
- mono_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
+ mono_coop_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
- mono_mutex_unlock (&threadpool_io->updates_lock);
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
}
void
if (!mono_lazy_is_initialized (&io_status))
return;
- mono_mutex_lock (&threadpool_io->updates_lock);
+ mono_coop_mutex_lock (&threadpool_io->updates_lock);
update = update_get_new ();
update->type = UPDATE_REMOVE_DOMAIN;
selector_thread_wakeup ();
- mono_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
+ mono_coop_cond_wait (&threadpool_io->updates_cond, &threadpool_io->updates_lock);
- mono_mutex_unlock (&threadpool_io->updates_lock);
+ mono_coop_mutex_unlock (&threadpool_io->updates_lock);
}
#else