[threads] Allow resetting the name of a threadpool thread (#4350)
[mono.git] / mono / metadata / attach.c
index 5e1605fd972295a21362b31a4be27f3d4f7d61a7..1f2e0fd103d93fc73768878b4f0c3181f40de996 100644 (file)
@@ -24,8 +24,6 @@
 #include <sys/stat.h>
 #include <sys/un.h>
 #include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #include <pwd.h>
@@ -42,6 +40,8 @@
 #include <mono/utils/mono-threads.h>
 #include "attach.h"
 
+#include <mono/utils/w32api.h>
+
 /*
  * This module enables other processes to attach to a running mono process and
  * load agent assemblies. 
@@ -94,7 +94,7 @@ static char *ipc_filename;
 
 static char *server_uri;
 
-static HANDLE receiver_thread_handle;
+static MonoThreadHandle *receiver_thread_handle;
 
 static gboolean stop_receiver_thread;
 
@@ -102,7 +102,7 @@ static gboolean needs_to_start, started;
 
 static void transport_connect (void);
 
-static guint32 WINAPI receiver_thread (void *arg);
+static gsize WINAPI receiver_thread (void *arg);
 
 static void transport_start_receive (void);
 
@@ -260,7 +260,7 @@ mono_attach_cleanup (void)
 
        /* Wait for the receiver thread to exit */
        if (receiver_thread_handle)
-               WaitForSingleObjectEx (receiver_thread_handle, 0, FALSE);
+               mono_thread_info_wait_one_handle (receiver_thread_handle, 0, FALSE);
 }
 
 static int
@@ -480,11 +480,11 @@ transport_start_receive (void)
        if (!listen_fd)
                return;
 
-       receiver_thread_handle = mono_threads_create_thread (receiver_thread, NULL, 0, 0, NULL);
+       receiver_thread_handle = mono_threads_create_thread (receiver_thread, NULL, NULL, NULL);
        g_assert (receiver_thread_handle);
 }
 
-static guint32 WINAPI
+static gsize WINAPI
 receiver_thread (void *arg)
 {
        MonoError error;
@@ -493,7 +493,7 @@ receiver_thread (void *arg)
        guint8 *p, *p_end;
        MonoObject *exc;
 
-       mono_thread_info_set_name (mono_native_thread_id_get (), "Attach receiver");
+       mono_native_thread_set_name (mono_native_thread_id_get (), "Attach receiver");
 
        printf ("attach: Listening on '%s'...\n", server_uri);
 
@@ -506,7 +506,7 @@ receiver_thread (void *arg)
                printf ("attach: Connected.\n");
 
                MonoThread *thread = mono_thread_attach (mono_get_root_domain ());
-               mono_thread_set_name_internal (thread->internal_thread, mono_string_new (mono_get_root_domain (), "Attach receiver"), TRUE, &error);
+               mono_thread_set_name_internal (thread->internal_thread, mono_string_new (mono_get_root_domain (), "Attach receiver"), TRUE, FALSE, &error);
                mono_error_assert_ok (&error);
                /* Ask the runtime to not abort this thread */
                //mono_thread_current ()->flags |= MONO_THREAD_FLAG_DONT_MANAGE;