emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

add pthread_set_name_np support


From: Timo Myyrä
Subject: add pthread_set_name_np support
Date: Sat, 27 Jun 2020 13:49:24 +0300

Hi,

While browsing the emacs code I noticed that pthread_set_name_np is not
supported by emacs currently. Here's simple diff to add it.
I'm not that well versed in autoconf, probably should check pthread_set_name_np
within the pthread_setname_np block so both won't get enabled at the same time.

Also I'm not sure if name should be padded, quickly looking OpenBSD sources
didn't indicate that padding would be required. LLVM code base seems to pad name
argument to max 16 chars on FreeBSD and 32 on OpenBSD.

Thoughts?

Timo


diff --git a/configure.ac b/configure.ac
index b1b8c846e1..cfc642f72e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4187,7 +4187,8 @@ AC_DEFUN
 sendto recvfrom getsockname getifaddrs freeifaddrs \
 gai_strerror sync \
 getpwent endpwent getgrent endgrent \
-cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np)
+cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \
+pthread_set_name_np)
 LIBS=$OLD_LIBS
 
 if test "$ac_cv_func_pthread_setname_np" = "yes"; then
@@ -4222,6 +4223,23 @@ AC_DEFUN
   fi
 fi
 
+if test "$ac_cv_func_pthread_set_name_np" = "yes"; then
+  AC_CACHE_CHECK(
+   [whether pthread_set_name_np is supported],
+   [emacs_cv_pthread_set_name_np],
+   [AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM(
+       [[#include <pthread.h>][#incule <pthread_np.h>]],
+       [[pthread_setname_np (1, "a");]])],
+     [emacs_cv_pthread_set_name_np=yes],
+     [emacs_cv_pthread_set_name_np=no])])
+  if test "$emacs_cv_pthread_set_name_np" = "yes"; then
+    AC_DEFINE(
+      HAVE_PTHREAD_SET_NAME_NP, 1,
+      [Define to 1 if pthread_set_name_np is supported.])
+  fi
+fi
+
 dnl No need to check for posix_memalign if aligned_alloc works.
 AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break])
 AC_CHECK_DECLS([aligned_alloc], [], [], [[#include <stdlib.h>]])
diff --git a/src/systhread.c b/src/systhread.c
index 0d600d6895..3087f18d4c 100644
--- a/src/systhread.c
+++ b/src/systhread.c
@@ -26,6 +26,10 @@ Copyright (C) 2012-2020 Free Software Foundation, Inc.
 #include "nsterm.h"
 #endif
 
+#ifdef HAVE_PTHREAD_SET_NAME_NP
+#include "pthread_np.h"
+#endif
+
 #ifndef THREADS_ENABLED
 
 void
@@ -222,6 +226,9 @@ #define TASK_COMM_LEN 16
   pthread_setname_np (pthread_self (), p_name);
 # endif
 #endif
+#ifdef HAVE_PTHREAD_SET_NAME_NP
+  pthread_set_name_np (pthread_self (), name);
+#endif
 }
 
 bool



reply via email to

[Prev in Thread] Current Thread [Next in Thread]