From 0e19b5d757d88eedd23709a4ea40aa1512a1ff21 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 20 Dec 2019 20:59:07 +0200 Subject: Support setting OS names of threads on MS-Windows * src/w32fns.c (setup_w32_kbdhook): Don't initialize is_debugger_present here... (globals_of_w32fns): ...initialize it here. Also initialize the new global variable set_thread_description. * src/systhread.c: [WINDOWSNT] Include mbctype.h (w32_set_thread_name): New function. (MS_VC_EXCEPTION): New macro. (THREADNAME_INFO, IsDebuggerPresent_Proc) (SetThreadDescription_Proc): New typedefs. (w32_beginthread_wrapper): Call w32_set_thread_name to set the name of the new thread. * src/thread.h (struct thread_state): New member thread_name. * src/thread.c (Fmake_thread): Set the thread_name field of the new thread object. (run_thread): Free the thread_name member after the thread exits. --- src/thread.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index e2deadd7a83..42c2bf52d28 100644 --- a/src/thread.c +++ b/src/thread.c @@ -756,6 +756,8 @@ run_thread (void *state) } } + xfree (self->thread_name); + current_thread = NULL; sys_cond_broadcast (&self->thread_condvar); @@ -825,6 +827,10 @@ If NAME is given, it must be a string; it names the new thread. */) all_threads = new_thread; char const *c_name = !NILP (name) ? SSDATA (ENCODE_UTF_8 (name)) : NULL; + if (c_name) + new_thread->thread_name = xstrdup (c_name); + else + new_thread->thread_name = NULL; sys_thread_t thr; if (! sys_thread_create (&thr, c_name, run_thread, new_thread)) { -- cgit v1.2.1