};
typedef struct {
- CRITICAL_SECTION io_lock; /* access to sock_to_state */
+ mono_mutex_t io_lock; /* access to sock_to_state */
int inited; // 0 -> not initialized , 1->initializing, 2->initialized, 3->cleaned up
MonoGHashTable *sock_to_state;
static MonoClass *process_async_call_klass;
static GPtrArray *wsqs;
-CRITICAL_SECTION wsqs_lock;
+mono_mutex_t wsqs_lock;
static gboolean suspended;
/* Hooks */
static void
socket_io_cleanup (SocketIOData *data)
{
- EnterCriticalSection (&data->io_lock);
+ mono_mutex_lock (&data->io_lock);
if (data->inited != 2) {
- LeaveCriticalSection (&data->io_lock);
+ mono_mutex_unlock (&data->io_lock);
return;
}
data->inited = 3;
data->shutdown (data->event_data);
- LeaveCriticalSection (&data->io_lock);
+ mono_mutex_unlock (&data->io_lock);
}
static int
if (socket_io_data.inited == 0)
return;
- EnterCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_lock (&socket_io_data.io_lock);
if (socket_io_data.sock_to_state == NULL) {
- LeaveCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_unlock (&socket_io_data.io_lock);
return;
}
list = mono_g_hash_table_lookup (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
if (list)
mono_g_hash_table_remove (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
- LeaveCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_unlock (&socket_io_data.io_lock);
while (list) {
state = (MonoSocketAsyncResult *) mono_mlist_get_data (list);
}
}
- EnterCriticalSection (&data->io_lock);
+ mono_mutex_lock (&data->io_lock);
data->sock_to_state = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC);
#ifdef HAVE_EPOLL
data->event_system = EPOLL_BACKEND;
data->event_system = POLL_BACKEND;
init_event_system (data);
- mono_thread_create_internal (mono_get_root_domain (), data->wait, data, TRUE, FALSE, SMALL_STACK);
- LeaveCriticalSection (&data->io_lock);
+ mono_thread_create_internal (mono_get_root_domain (), data->wait, data, TRUE, SMALL_STACK);
+ mono_mutex_unlock (&data->io_lock);
data->inited = 2;
threadpool_start_thread (&async_io_tp);
}
MONO_OBJECT_SETREF (state, ares, ares);
fd = GPOINTER_TO_INT (state->handle);
- EnterCriticalSection (&data->io_lock);
+ mono_mutex_lock (&data->io_lock);
if (data->sock_to_state == NULL) {
- LeaveCriticalSection (&data->io_lock);
+ mono_mutex_unlock (&data->io_lock);
return;
}
list = mono_g_hash_table_lookup (data->sock_to_state, GINT_TO_POINTER (fd));
#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
#endif
- mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
+ mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
SleepEx (100, TRUE);
} while (1);
}
g_print ("Queued: %d\n", (tp->tail - tp->head));
if (tp == &async_tp) {
int i;
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
for (i = 0; i < wsqs->len; i++) {
g_print ("\tWSQ %d: %d\n", i, mono_wsq_count (g_ptr_array_index (wsqs, i)));
}
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
} else {
g_print ("\tSockets: %d\n", mono_g_hash_table_size (socket_io_data.sock_to_state));
}
continue;
need_one = (mono_cq_count (tp->queue) > 0);
if (!need_one && !tp->is_io) {
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
MonoWSQ *wsq;
wsq = g_ptr_array_index (wsqs, i);
break;
}
}
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
}
if (need_one)
threadpool_start_thread (tp);
}
MONO_GC_REGISTER_ROOT_FIXED (socket_io_data.sock_to_state);
- InitializeCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_init_recursive (&socket_io_data.io_lock);
if (g_getenv ("MONO_THREADS_PER_CPU") != NULL) {
threads_per_cpu = atoi (g_getenv ("MONO_THREADS_PER_CPU"));
if (threads_per_cpu < 1)
async_call_klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
g_assert (async_call_klass);
- InitializeCriticalSection (&wsqs_lock);
+ mono_mutex_init_recursive (&wsqs_lock);
wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
#ifndef DISABLE_PERFCOUNTERS
}
if (wsqs) {
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
mono_wsq_cleanup ();
if (wsqs)
g_ptr_array_free (wsqs, TRUE);
wsqs = NULL;
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
MONO_SEM_DESTROY (&async_tp.new_job);
}
}
#ifndef DISABLE_PERFCOUNTERS
mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
#endif
- mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
+ mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
return TRUE;
}
}
if (tp->pool_status == 0 && InterlockedCompareExchange (&tp->pool_status, 1, 0) == 0) {
if (!tp->is_io) {
- mono_thread_create_internal (mono_get_root_domain (), monitor_thread, NULL, TRUE, FALSE, SMALL_STACK);
+ mono_thread_create_internal (mono_get_root_domain (), monitor_thread, NULL, TRUE, SMALL_STACK);
threadpool_start_thread (tp);
}
/* Create on demand up to min_threads to avoid startup penalty for apps that don't use
* the threadpool that much
*/
if (mono_config_is_server_mode ()) {
- mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, FALSE, SMALL_STACK);
+ mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, SMALL_STACK);
}
}
threadpool_clear_queue (&async_tp, domain);
threadpool_clear_queue (&async_io_tp, domain);
- EnterCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_lock (&socket_io_data.io_lock);
if (socket_io_data.sock_to_state)
mono_g_hash_table_foreach_remove (socket_io_data.sock_to_state, remove_sockstate_for_domain, domain);
- LeaveCriticalSection (&socket_io_data.io_lock);
+ mono_mutex_unlock (&socket_io_data.io_lock);
/*
* There might be some threads out that could be about to execute stuff from the given domain.
int i;
MonoWSQ *wsq;
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
wsq = mono_wsq_create ();
if (wsqs == NULL) {
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
return NULL;
}
for (i = 0; i < wsqs->len; i++) {
if (g_ptr_array_index (wsqs, i) == NULL) {
wsqs->pdata [i] = wsq;
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
return wsq;
}
}
g_ptr_array_add (wsqs, wsq);
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
return wsq;
}
if (wsq == NULL)
return;
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
if (wsqs == NULL) {
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
return;
}
g_ptr_array_remove_fast (wsqs, wsq);
}
}
mono_wsq_destroy (wsq);
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
}
static void
if (mono_runtime_is_shutting_down ())
return;
- EnterCriticalSection (&wsqs_lock);
+ mono_mutex_lock (&wsqs_lock);
for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
MonoWSQ *wsq;
continue;
mono_wsq_try_steal (wsqs->pdata [i], data, ms);
if (*data != NULL) {
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
return;
}
}
- LeaveCriticalSection (&wsqs_lock);
+ mono_mutex_unlock (&wsqs_lock);
ms += 10;
} while (retry && ms < 11);
}
static gboolean
dequeue_or_steal (ThreadPool *tp, gpointer *data, MonoWSQ *local_wsq)
{
- if (mono_runtime_is_shutting_down ())
+ MonoCQ *queue = tp->queue;
+ if (mono_runtime_is_shutting_down () || !queue)
return FALSE;
- mono_cq_dequeue (tp->queue, (MonoObject **) data);
+ mono_cq_dequeue (queue, (MonoObject **) data);
if (!tp->is_io && !*data)
try_steal (local_wsq, data, FALSE);
return (*data != NULL);
InterlockedExchange (&async_tp.min_threads, workerThreads);
InterlockedExchange (&async_io_tp.min_threads, completionPortThreads);
if (workerThreads > async_tp.nthreads)
- mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_tp, TRUE, FALSE, SMALL_STACK);
+ mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_tp, TRUE, SMALL_STACK);
if (completionPortThreads > async_io_tp.nthreads)
- mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_io_tp, TRUE, FALSE, SMALL_STACK);
+ mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_io_tp, TRUE, SMALL_STACK);
return TRUE;
}