]> git.eshelyaron.com Git - emacs.git/commitdiff
Use pthread_setname_np to set thread name
authorRobert Pluim <rpluim@gmail.com>
Thu, 19 Dec 2019 16:33:16 +0000 (17:33 +0100)
committerRobert Pluim <rpluim@gmail.com>
Mon, 6 Jan 2020 14:27:26 +0000 (15:27 +0100)
* configure.ac: Remove check for sys/prctl.h and prctl, check for
pthread_setname_np instead.

* systhread.c: Remove sys/prctl.h include.
(sys_thread_create) [HAVE_PTHREAD_SETNAME_NP]: Use pthread_setname_np
to set the name of the newly created thread (Bug#38632).

* thread.c (Fmake_thread): Use ENCODE_SYSTEM instead of
ENCODE_UTF_8 on the thread name.

configure.ac
src/systhread.c
src/thread.c

index 39bfcf598860e466bfd7aa81907e63c80d55037a..de4710f150a767a4ce3531e4c299d9c2d110a77e 100644 (file)
@@ -1767,7 +1767,7 @@ AC_CHECK_HEADERS_ONCE(
   sys/sysinfo.h
   coff.h pty.h
   sys/resource.h
-  sys/utsname.h pwd.h utmp.h util.h sys/prctl.h)
+  sys/utsname.h pwd.h utmp.h util.h)
 
 AC_CACHE_CHECK([for ADDR_NO_RANDOMIZE],
   [emacs_cv_personality_addr_no_randomize],
@@ -4180,7 +4180,7 @@ pthread_sigmask strsignal setitimer timer_getoverrun \
 sendto recvfrom getsockname getifaddrs freeifaddrs \
 gai_strerror sync \
 getpwent endpwent getgrent endgrent \
-cfmakeraw cfsetspeed __executable_start log2 prctl)
+cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np)
 LIBS=$OLD_LIBS
 
 dnl No need to check for posix_memalign if aligned_alloc works.
index c3e4e6a2c5a707bf3af13bfba6c4f334deeb28d2..1dda036cc2fc20a8e19355b51bd5e84dc27d997f 100644 (file)
@@ -98,10 +98,6 @@ sys_thread_yield (void)
 
 #include <sched.h>
 
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
-
 void
 sys_mutex_init (sys_mutex_t *mutex)
 {
@@ -227,9 +223,18 @@ sys_thread_create (sys_thread_t *thread_ptr, const char *name,
   if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED))
     {
       result = pthread_create (thread_ptr, &attr, func, arg) == 0;
-#if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME)
+#ifdef HAVE_PTHREAD_SETNAME_NP
       if (result && name != NULL)
-       prctl (PR_SET_NAME, name);
+        {
+          /* We need to truncate here otherwise pthread_setname_np
+             fails to set the name.  TASK_COMM_LEN is what the length
+             is called in the Linux kernel headers (Bug#38632).  */
+#define TASK_COMM_LEN 16
+          char p_name[TASK_COMM_LEN];
+          strncpy (p_name, name, TASK_COMM_LEN - 1);
+          p_name[TASK_COMM_LEN - 1] = '\0';
+          pthread_setname_np (*thread_ptr, p_name);
+        }
 #endif
     }
 
index f81163414bbb39cf1ffd1aadb93a4bae7888fe39..f7e39dc42730e773c76d1df883dc1f38b2a58c0a 100644 (file)
@@ -826,7 +826,7 @@ If NAME is given, it must be a string; it names the new thread.  */)
   new_thread->next_thread = all_threads;
   all_threads = new_thread;
 
-  char const *c_name = !NILP (name) ? SSDATA (ENCODE_UTF_8 (name)) : NULL;
+  char const *c_name = !NILP (name) ? SSDATA (ENCODE_SYSTEM (name)) : NULL;
   if (c_name)
     new_thread->thread_name = xstrdup (c_name);
   else