util: Handle differences in pthread_setname_np
authorMatt Turner <mattst88@gmail.com>
Wed, 31 Jul 2019 21:44:39 +0000 (14:44 -0700)
committerEric Engestrom <eric.engestrom@intel.com>
Fri, 2 Aug 2019 17:38:52 +0000 (18:38 +0100)
There are a lot of unfortunate differences in the implementation of this
function. NetBSD and Mac OS X in particular require different arguments.

https://stackoverflow.com/questions/2369738/how-to-set-the-name-of-a-thread-in-linux-pthreads/7989973#7989973
provides for a good overview of the differences.

Fixes: 9c411e020d1 ("util: Drop preprocessor guards for glibc-2.12")
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111264
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
[Eric: use DETECT_OS_* instead of PIPE_OS_*]
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/util/u_thread.h

index 8c8cc803199ce6c6d16f94eedd317ecd51d43943..b240b446aa28bf00211444f9453a5337aabe9869 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdbool.h>
 
 #include "c11/threads.h"
+#include "detect_os.h"
 
 #ifdef HAVE_PTHREAD
 #include <signal.h>
@@ -61,7 +62,17 @@ static inline thrd_t u_thread_create(int (*routine)(void *), void *param)
 static inline void u_thread_setname( const char *name )
 {
 #if defined(HAVE_PTHREAD)
+#if DETECT_OS_LINUX
    pthread_setname_np(pthread_self(), name);
+#elif DETECT_OS_FREEBSD || DETECT_OS_OPENBSD
+   pthread_set_name_np(pthread_self(), name);
+#elif DETECT_OS_NETBSD
+   pthread_setname_np(pthread_self(), "%s", name);
+#elif DETECT_OS_APPLE
+   pthread_setname_np(name);
+#else
+#error Not sure how to call pthread_setname_np
+#endif
 #endif
    (void)name;
 }