diff options
author | Chris Robinson <[email protected]> | 2017-09-15 22:09:37 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-09-19 10:05:41 -0700 |
commit | eaf3b9414384dbb8db73a887d1af9ed094a35dd5 (patch) | |
tree | 36632e2513630f9bd649a61efd8fe0e70eed2d07 | |
parent | 84eca96dad71ea335af1bcdd8f79f78b4a11b52f (diff) |
Add a check for pthread_setname_np with three parameters
As found in NetBSD.
-rw-r--r-- | CMakeLists.txt | 19 | ||||
-rw-r--r-- | common/threads.c | 2 | ||||
-rw-r--r-- | config.h.in | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 14d77073..b3bca83a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -623,6 +623,16 @@ int main() }" PTHREAD_SETNAME_NP_ONE_PARAM ) + CHECK_C_SOURCE_COMPILES(" +#include <pthread.h> +#include <pthread_np.h> +int main() +{ + pthread_setname_np(pthread_self(), \"%s\", \"testname\"); + return 0; +}" + PTHREAD_SETNAME_NP_THREE_PARAMS + ) ENDIF() CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP) ELSE() @@ -639,6 +649,15 @@ int main() }" PTHREAD_SETNAME_NP_ONE_PARAM ) + CHECK_C_SOURCE_COMPILES(" +#include <pthread.h> +int main() +{ + pthread_setname_np(pthread_self(), \"%s\", \"testname\"); + return 0; +}" + PTHREAD_SETNAME_NP_THREE_PARAMS + ) ENDIF() CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP) ENDIF() diff --git a/common/threads.c b/common/threads.c index 0761a324..dbd196e8 100644 --- a/common/threads.c +++ b/common/threads.c @@ -500,6 +500,8 @@ void althrd_setname(althrd_t thr, const char *name) #if defined(PTHREAD_SETNAME_NP_ONE_PARAM) if(althrd_equal(thr, althrd_current())) pthread_setname_np(name); +#elif defined(PTHREAD_SETNAME_NP_THREE_PARAMS) + pthread_setname_np(thr, "%s", (void*)name); #else pthread_setname_np(thr, name); #endif diff --git a/config.h.in b/config.h.in index 56a78448..b0fc5d2b 100644 --- a/config.h.in +++ b/config.h.in @@ -194,6 +194,9 @@ /* Define if pthread_setname_np() only accepts one parameter */ #cmakedefine PTHREAD_SETNAME_NP_ONE_PARAM +/* Define if pthread_setname_np() accepts three parameters */ +#cmakedefine PTHREAD_SETNAME_NP_THREE_PARAMS + /* Define if we have pthread_set_name_np() */ #cmakedefine HAVE_PTHREAD_SET_NAME_NP |