From 7690c229b166c84461bfeb95e4b950443b331293 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:47:56 +0000 Subject: [PATCH 1/2] util: Document platforms in `SetOsThreadName()` branches --- src/mp/util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mp/util.cpp b/src/mp/util.cpp index e9710eaa..6826d0b4 100644 --- a/src/mp/util.cpp +++ b/src/mp/util.cpp @@ -181,13 +181,13 @@ 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(name)); + pthread_setname_np(pthread_self(), "%s", const_cast(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(__APPLE__) - pthread_setname_np(name); + pthread_setname_np(name); // macOS #else // Prevent warnings for unused parameters... (void)name; From 1a59d5d0a82620f8ec748b05e203316a79feb806 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:02:12 +0000 Subject: [PATCH 2/2] build, util: Add `HAVE_PTHREAD_SETNAME_NP_2ARG` configuration macro On platforms that provide only the 2-argument `pthread_setname_np()` function, such as illumos, none of the branches in `SetOsThreadName()` matches, so threads are left unnamed. As `pthread_getname_np()` is available there, the thread name tests fail. Introduce the `HAVE_PTHREAD_SETNAME_NP_2ARG` configuration macro, which represents the availability of that function, and use it in `SetOsThreadName()`. Platforms already handled by another branch are not affected. --- cmake/pthread_checks.cmake | 8 ++++++++ include/mp/config.h.in | 1 + src/mp/util.cpp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/cmake/pthread_checks.cmake b/cmake/pthread_checks.cmake index c5e6d98b..c52ed22a 100644 --- a/cmake/pthread_checks.cmake +++ b/cmake/pthread_checks.cmake @@ -19,6 +19,14 @@ check_cxx_source_compiles(" }" HAVE_PTHREAD_GETNAME_NP) +check_cxx_source_compiles(" + #include + int main() + { + return pthread_setname_np(pthread_self(), \"name\"); + }" + HAVE_PTHREAD_SETNAME_NP_2ARG) + check_cxx_source_compiles(" #include int main() diff --git a/include/mp/config.h.in b/include/mp/config.h.in index b4ca6ded..05223b70 100644 --- a/include/mp/config.h.in +++ b/include/mp/config.h.in @@ -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@ diff --git a/src/mp/util.cpp b/src/mp/util.cpp index 6826d0b4..e13eea2a 100644 --- a/src/mp/util.cpp +++ b/src/mp/util.cpp @@ -186,6 +186,8 @@ void SetOsThreadName(const char* name) pthread_setname_np(pthread_self(), "%s", const_cast(name)); // NetBSD #elif defined(HAVE_PTHREAD_GETTHREADID_NP) 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); // macOS #else