Skip to content

Commit 8315084

Browse files
committed
Cater for 3-argument version of pthread_setname_np
Fixes Bug#39363. * configure.ac: Add check for 3-argument version of pthread_setname_np. * src/systhread.c (sys_thread_set_name) [HAVE_PTHREAD_SETNAME_NP_3ARG]: Call pthread_setname_np with 3 arguments.
1 parent f27187f commit 8315084

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,6 +4197,21 @@ if test "$ac_cv_func_pthread_setname_np" = "yes"; then
41974197
AC_DEFINE(
41984198
HAVE_PTHREAD_SETNAME_NP_1ARG, 1,
41994199
[Define to 1 if pthread_setname_np takes a single argument.])
4200+
else
4201+
AC_CACHE_CHECK(
4202+
[whether pthread_setname_np takes three arguments],
4203+
[emacs_cv_pthread_setname_np_3arg],
4204+
[AC_COMPILE_IFELSE(
4205+
[AC_LANG_PROGRAM(
4206+
[[#include <pthread.h>]],
4207+
[[pthread_setname_np (0, "%s", "a");]])],
4208+
[emacs_cv_pthread_setname_np_3arg=yes],
4209+
[emacs_cv_pthread_setname_np_3arg=no])])
4210+
if test "$emacs_cv_pthread_setname_np_3arg" = "yes"; then
4211+
AC_DEFINE(
4212+
HAVE_PTHREAD_SETNAME_NP_3ARG, 1,
4213+
[Define to 1 if pthread_setname_np takes three arguments.])
4214+
fi
42004215
fi
42014216
fi
42024217

src/systhread.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ sys_thread_set_name (const char *name)
214214
char p_name[TASK_COMM_LEN];
215215
strncpy (p_name, name, TASK_COMM_LEN - 1);
216216
p_name[TASK_COMM_LEN - 1] = '\0';
217-
#ifdef HAVE_PTHREAD_SETNAME_NP_1ARG
217+
# ifdef HAVE_PTHREAD_SETNAME_NP_1ARG
218218
pthread_setname_np (p_name);
219-
#else
219+
# elif defined HAVE_PTHREAD_SETNAME_NP_3ARG
220+
pthread_setname_np (pthread_self (), "%s", p_name);
221+
# else
220222
pthread_setname_np (pthread_self (), p_name);
221-
#endif
223+
# endif
222224
#endif
223225
}
224226

0 commit comments

Comments
 (0)