[threadpool] Pass callback at initialization (#4546)
[mono.git] / mono / metadata / threadpool.c
index f3ff6b6ac7d061d0bd9cbb0214bffed9ed37ecfb..3c0fa3d7f6db0ebda4cd140ae42d6f7a7b60e716 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * threadpool.c: Microsoft threadpool runtime support
+/**
+ * \file
+ * Microsoft threadpool runtime support
  *
  * Author:
  *     Ludovic Henry (ludovic.henry@xamarin.com)
@@ -121,6 +122,9 @@ destroy (gpointer unused)
        mono_coop_mutex_destroy (&threadpool.domains_lock);
 }
 
+static void
+worker_callback (void);
+
 static void
 initialize (void)
 {
@@ -134,7 +138,7 @@ initialize (void)
        threadpool.limit_io_min = mono_cpu_count ();
        threadpool.limit_io_max = CLAMP (threadpool.limit_io_min * 100, MIN (threadpool.limit_io_min, 200), MAX (threadpool.limit_io_min, 200));
 
-       mono_threadpool_worker_init ();
+       mono_threadpool_worker_init (worker_callback);
 }
 
 static void
@@ -154,7 +158,7 @@ mono_threadpool_enqueue_work_item (MonoDomain *domain, MonoObject *work_item, Mo
        MonoBoolean f;
        gpointer args [2];
 
-       mono_error_init (error);
+       error_init (error);
        g_assert (work_item);
 
        if (!threadpool_class)
@@ -270,13 +274,13 @@ static MonoObject*
 try_invoke_perform_wait_callback (MonoObject** exc, MonoError *error)
 {
        HANDLE_FUNCTION_ENTER ();
-       mono_error_init (error);
+       error_init (error);
        MonoObject *res = mono_runtime_try_invoke (mono_defaults.threadpool_perform_wait_callback_method, NULL, NULL, exc, error);
        HANDLE_FUNCTION_RETURN_VAL (res);
 }
 
 static void
-worker_callback (gpointer unused)
+worker_callback (void)
 {
        MonoError error;
        ThreadPoolDomain *tpdomain, *previous_tpdomain;
@@ -420,7 +424,7 @@ mono_threadpool_begin_invoke (MonoDomain *domain, MonoObject *target, MonoMethod
        if (!async_call_klass)
                async_call_klass = mono_class_load_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
 
-       mono_error_init (error);
+       error_init (error);
 
        message = mono_method_call_message_new (method, params, mono_get_delegate_invoke (method->klass), (params != NULL) ? (&async_callback) : NULL, (params != NULL) ? (&state) : NULL, error);
        return_val_if_nok (error, NULL);
@@ -451,7 +455,7 @@ mono_threadpool_end_invoke (MonoAsyncResult *ares, MonoArray **out_args, MonoObj
 {
        MonoAsyncCall *ac;
 
-       mono_error_init (error);
+       error_init (error);
        g_assert (exc);
        g_assert (out_args);
 
@@ -778,7 +782,7 @@ ves_icall_System_Threading_ThreadPool_RequestWorkerThread (void)
                counter._.starting ++;
        });
 
-       mono_threadpool_worker_enqueue (worker_callback, NULL);
+       mono_threadpool_worker_request ();
 
        mono_refcount_dec (&threadpool);
        return TRUE;