Skip to content

Commit

Permalink
Use pthread_set_name_np when it available
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed Nov 19, 2024
1 parent 489bcc0 commit 61d5be6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/varnishd/cache/cache_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ THR_GetWorker(void)

static pthread_key_t name_key;

#ifdef HAVE_PTHREAD_SETNAME_NP
static void
thr_setname_generic(const char *name)
{
Expand All @@ -146,18 +147,23 @@ thr_setname_generic(const char *name)
//lint --e{438} Last value assigned not used
PTOK(pthread_setname_np(pthread_self(), name));
}
#endif

void
THR_SetName(const char *name)
{

PTOK(pthread_setspecific(name_key, name));
#if defined(__APPLE__)
#if defined(HAVE_PTHREAD_SETNAME_NP)
# if defined(__APPLE__)
(void)pthread_setname_np(name);
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
(void)pthread_setname_np(pthread_self(), "%s", (char *)(uintptr_t)name);
#else
# else
thr_setname_generic(name);
# endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
(void)pthread_set_name_np(pthread_self(), name);
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ AC_CHECK_FUNCS([fnmatch], [], [AC_MSG_ERROR([fnmatch(3) is required])])

save_LIBS="${LIBS}"
LIBS="${PTHREAD_LIBS}"
AC_CHECK_FUNCS([pthread_setname_np])
AC_CHECK_FUNCS([pthread_set_name_np])
AC_CHECK_FUNCS([pthread_mutex_isowned_np])
AC_CHECK_FUNCS([pthread_getattr_np])
LIBS="${save_LIBS}"
Expand Down

0 comments on commit 61d5be6

Please sign in to comment.