Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / threadpool.c
index 0b36a37cee925f982d5d36686cbfecfb4e31e881..a1424beaebaea483723c7cda7050bed4182730f6 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * threadpool.c: Microsoft threadpool runtime support
+/**
+ * \file
+ * Microsoft threadpool runtime support
  *
  * Author:
  *     Ludovic Henry (ludovic.henry@xamarin.com)
@@ -45,6 +46,7 @@
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/refcount.h>
+#include <mono/utils/mono-os-wait.h>
 
 typedef struct {
        MonoDomain *domain;
@@ -121,6 +123,9 @@ destroy (gpointer unused)
        mono_coop_mutex_destroy (&threadpool.domains_lock);
 }
 
+static void
+worker_callback (void);
+
 static void
 initialize (void)
 {
@@ -134,7 +139,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
@@ -276,7 +281,7 @@ try_invoke_perform_wait_callback (MonoObject** exc, MonoError *error)
 }
 
 static void
-worker_callback (gpointer unused)
+worker_callback (void)
 {
        MonoError error;
        ThreadPoolDomain *tpdomain, *previous_tpdomain;
@@ -335,14 +340,16 @@ worker_callback (gpointer unused)
                g_assert (tpdomain->outstanding_request >= 0);
 
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_THREADPOOL, "[%p] worker running in domain %p (outstanding requests %d)",
-                       mono_native_thread_id_get (), tpdomain->domain, tpdomain->outstanding_request);
+                       GUINT_TO_POINTER (MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ())), tpdomain->domain, tpdomain->outstanding_request);
 
                g_assert (tpdomain->threadpool_jobs >= 0);
                tpdomain->threadpool_jobs ++;
 
                domains_unlock ();
 
-               mono_thread_set_name_internal (thread, mono_string_new (mono_get_root_domain (), "Threadpool worker"), FALSE, TRUE, &error);
+               MonoString *thread_name = mono_string_new_checked (mono_get_root_domain (), "Threadpool worker", &error);
+               mono_error_assert_ok (&error);
+               mono_thread_set_name_internal (thread, thread_name, FALSE, TRUE, &error);
                mono_error_assert_ok (&error);
 
                mono_thread_clr_state (thread, (MonoThreadState)~ThreadState_Background);
@@ -489,7 +496,7 @@ mono_threadpool_end_invoke (MonoAsyncResult *ares, MonoArray **out_args, MonoObj
                mono_monitor_exit ((MonoObject*) ares);
                MONO_ENTER_GC_SAFE;
 #ifdef HOST_WIN32
-               WaitForSingleObjectEx (wait_event, INFINITE, TRUE);
+               mono_win32_wait_for_single_object_ex (wait_event, INFINITE, TRUE);
 #else
                mono_w32handle_wait_one (wait_event, MONO_INFINITE_WAIT, TRUE);
 #endif
@@ -778,7 +785,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;