Skip to content

Commit

Permalink
Detect pthread_getname_np explicitly.
Browse files Browse the repository at this point in the history
At least one libc (musl) defines pthread_setname_np without defining
pthread_getname_np. Detect the presence of each individually, rather than
inferring both must be defined if set is.
  • Loading branch information
devnexen authored and davidtgoldblatt committed Nov 12, 2020
1 parent b3c5690 commit 95f0a77
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
31 changes: 31 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,37 @@ dnl Check if we have dlsym support.
if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
fi
dnl Check if pthread_getname_np is not necessarily present despite
dnl the pthread_setname_np counterpart
JE_COMPILABLE([pthread_getname_np(3)], [
#include <pthread.h>
#include <stdlib.h>
], [
{
char *name = malloc(16);
pthread_getname_np(pthread_self(), name, 16);
free(name);
}
], [je_cv_pthread_getname_np])
if test "x${je_cv_pthread_getname_np}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_GETNAME_NP], [ ])
fi
dnl Check if pthread_get_name_np is not necessarily present despite
dnl the pthread_set_name_np counterpart
JE_COMPILABLE([pthread_get_name_np(3)], [
#include <pthread.h>
#include <pthread_np.h>
#include <stdlib.h>
], [
{
char *name = malloc(16);
pthread_get_name_np(pthread_self(), name, 16);
free(name);
}
], [je_cv_pthread_get_name_np])
if test "x${je_cv_pthread_get_name_np}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_GET_NAME_NP], [ ])
fi
fi

JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
Expand Down
6 changes: 6 additions & 0 deletions include/jemalloc/internal/jemalloc_internal_defs.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
/* Defined if pthread_setname_np(3) is available. */
#undef JEMALLOC_HAVE_PTHREAD_SETNAME_NP

/* Defined if pthread_getname_np(3) is available. */
#undef JEMALLOC_HAVE_PTHREAD_GETNAME_NP

/* Defined if pthread_get_name_np(3) is available. */
#undef JEMALLOC_HAVE_PTHREAD_GET_NAME_NP

/*
* Defined if clock_gettime(CLOCK_MONOTONIC_COARSE, ...) is available.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/prof_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,11 @@ void prof_unwind_init() {

static int
prof_sys_thread_name_read_impl(char *buf, size_t limit) {
#ifdef JEMALLOC_HAVE_PTHREAD_SETNAME_NP
#if defined(JEMALLOC_HAVE_PTHREAD_GETNAME_NP)
return pthread_getname_np(pthread_self(), buf, limit);
#elif defined(JEMALLOC_HAVE_PTHREAD_GET_NAME_NP)
pthread_get_name_np(pthread_self(), buf, limit);
return 0;
#else
return ENOSYS;
#endif
Expand Down

0 comments on commit 95f0a77

Please sign in to comment.