From e4028d15153a29966425d93be6374fae770d14a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Myyr=C3=A4?= Date: Sun, 28 Jun 2020 10:27:21 +0200 Subject: [PATCH] Add thread-naming support for OpenBSD OpenBSD has pthread_set_name_np; FreeBSD appears to have both this call and pthread_setname_np (the latter call is used in preference). * configure.ac: Detect pthread_set_name_np. * sys/systhread.c: Include and call pthread_set_name_np if available. --- configure.ac | 3 ++- src/systhread.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b1b8c846e14..9edd2273b19 100644 --- a/configure.ac +++ b/configure.ac @@ -4187,7 +4187,8 @@ pthread_sigmask strsignal setitimer timer_getoverrun \ 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 diff --git a/src/systhread.c b/src/systhread.c index 0d600d6895e..ebd75526495 100644 --- a/src/systhread.c +++ b/src/systhread.c @@ -26,6 +26,10 @@ along with GNU Emacs. If not, see . */ #include "nsterm.h" #endif +#ifdef HAVE_PTHREAD_SET_NAME_NP +#include +#endif + #ifndef THREADS_ENABLED void @@ -221,6 +225,10 @@ sys_thread_set_name (const char *name) # else pthread_setname_np (pthread_self (), p_name); # endif +#elif HAVE_PTHREAD_SET_NAME_NP + /* The name will automatically be truncated if it exceeds a + system-specific length. */ + pthread_set_name_np (pthread_self (), name); #endif }