all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* add pthread_set_name_np support
@ 2020-06-27 10:49 Timo Myyrä
  2020-06-27 11:10 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Timo Myyrä @ 2020-06-27 10:49 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-29  8:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-27 10:49 add pthread_set_name_np support Timo Myyrä
2020-06-27 11:10 ` Eli Zaretskii
2020-06-27 12:51   ` Timo Myyrä
     [not found]     ` <C3EA421C-D39D-4FA3-A5EE-417E50E746AC@acm.org>
     [not found]       ` <87pn9kpenx.fsf@asteroid.bittivirhe.fi>
     [not found]         ` <4992EBB9-BEA9-4629-BCA5-462A252C86DC@acm.org>
     [not found]           ` <87lfk8p88e.fsf@asteroid.bittivirhe.fi>
     [not found]             ` <0C52F7EC-B5D1-493A-97C2-0A94AC9550BC@acm.org>
     [not found]               ` <87sgefdbhj.fsf@asteroid.bittivirhe.fi>
2020-06-28  9:38                 ` Mattias Engdegård
2020-06-29  8:26     ` Robert Pluim
2020-06-27 13:42   ` Philipp Stephani

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.