Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmake/pthread_checks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ check_cxx_source_compiles("
}"
HAVE_PTHREAD_GETNAME_NP)

check_cxx_source_compiles("
#include <pthread.h>
int main()
{
return pthread_setname_np(pthread_self(), \"name\");
}"
HAVE_PTHREAD_SETNAME_NP_2ARG)

check_cxx_source_compiles("
#include <pthread.h>
int main()
Expand Down
1 change: 1 addition & 0 deletions include/mp/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#cmakedefine HAVE_KJ_FILESYSTEM

#cmakedefine HAVE_PTHREAD_GETNAME_NP @HAVE_PTHREAD_GETNAME_NP@
#cmakedefine HAVE_PTHREAD_SETNAME_NP_2ARG @HAVE_PTHREAD_SETNAME_NP_2ARG@
#cmakedefine HAVE_PTHREAD_SETNAME_NP_3ARG @HAVE_PTHREAD_SETNAME_NP_3ARG@
#cmakedefine HAVE_PTHREAD_THREADID_NP @HAVE_PTHREAD_THREADID_NP@
#cmakedefine HAVE_PTHREAD_GETTHREADID_NP @HAVE_PTHREAD_GETTHREADID_NP@
Expand Down
10 changes: 6 additions & 4 deletions src/mp/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ void SetOsThreadName(const char* name)
{
#if defined(PR_SET_NAME)
// Only the first 15 characters are used (16 - NUL terminator)
::prctl(PR_SET_NAME, name, 0, 0, 0);
::prctl(PR_SET_NAME, name, 0, 0, 0); // Linux
#elif defined(HAVE_PTHREAD_SETNAME_NP_3ARG)
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name));
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name)); // NetBSD
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
pthread_set_name_np(pthread_self(), name);
pthread_set_name_np(pthread_self(), name); // FreeBSD
#elif defined(HAVE_PTHREAD_SETNAME_NP_2ARG)
pthread_setname_np(pthread_self(), name); // illumos
#elif defined(__APPLE__)
pthread_setname_np(name);
pthread_setname_np(name); // macOS
#else
// Prevent warnings for unused parameters...
(void)name;
Expand Down
Loading