Skip to content

Commit a3f4977

Browse files
committed
Add thread name for background threads.
1 parent 52fc887 commit a3f4977

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,15 @@ if test "x$abi" != "xpecoff" ; then
14701470
if test "x${je_cv_pthread_atfork}" = "xyes" ; then
14711471
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
14721472
fi
1473+
dnl Check if pthread_setname_np is available with the expected API.
1474+
JE_COMPILABLE([pthread_setname_np(3)], [
1475+
#include <pthread.h>
1476+
], [
1477+
pthread_setname_np(pthread_self(), "setname_test");
1478+
], [je_cv_pthread_setname_np])
1479+
if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
1480+
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
1481+
fi
14731482
fi
14741483

14751484
JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)

include/jemalloc/internal/jemalloc_internal_defs.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
/* Defined if pthread_atfork(3) is available. */
9999
#undef JEMALLOC_HAVE_PTHREAD_ATFORK
100100

101+
/* Defined if pthread_setname_np(3) is available. */
102+
#undef JEMALLOC_HAVE_PTHREAD_SETNAME_NP
103+
101104
/*
102105
* Defined if clock_gettime(CLOCK_MONOTONIC_COARSE, ...) is available.
103106
*/

src/background_thread.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ static void *
499499
background_thread_entry(void *ind_arg) {
500500
unsigned thread_ind = (unsigned)(uintptr_t)ind_arg;
501501
assert(thread_ind < ncpus);
502-
502+
#ifdef JEMALLOC_HAVE_PTHREAD_SETNAME_NP
503+
pthread_setname_np(pthread_self(), "jemalloc_bg_thd");
504+
#endif
503505
if (opt_percpu_arena != percpu_arena_disabled) {
504506
set_current_thread_affinity((int)thread_ind);
505507
}

0 commit comments

Comments
 (0)