Bug 782111: Fix usage of pthread_set_name_np() on BSDs. r=wtc NSPR_4_12_BETA2
authorJan Beich <jbeich@tormail.org>
Sun, 31 Jan 2016 12:35:58 -0800
changeset 4676 85f6c6480115ab2542173fe9ccbb6e9a13aa7c38
parent 4675 091cfd3c8c1349a6a95571c09c2dbc70040f3971
child 4677 0ce879067b8c285bb6261a85bd16bc4b6b9ceafc
push id206
push userwtc@google.com
push dateSun, 31 Jan 2016 20:36:08 +0000
reviewerswtc
bugs782111
Bug 782111: Fix usage of pthread_set_name_np() on BSDs. r=wtc
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -16,16 +16,20 @@
 #include "prpdce.h"
 
 #include <pthread.h>
 #include <unistd.h>
 #include <string.h>
 #include <signal.h>
 #include <dlfcn.h>
 
+#if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY)
+#include <pthread_np.h>
+#endif
+
 #ifdef SYMBIAN
 /* In Open C sched_get_priority_min/max do not work properly, so we undefine
  * _POSIX_THREAD_PRIORITY_SCHEDULING here.
  */
 #undef _POSIX_THREAD_PRIORITY_SCHEDULING
 #endif
 
 #ifdef _PR_NICE_PRIORITY_SCHEDULING
@@ -1728,17 +1732,17 @@ PR_IMPLEMENT(void*)PR_GetSP(PRThread *th
 }  /* PR_GetSP */
 
 #endif /* !defined(_PR_DCETHREADS) */
 
 PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
 {
     PRThread *thread;
     size_t nameLen;
-    int result;
+    int result = 0;
 
     if (!name) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
 
     thread = PR_GetCurrentThread();
     if (!thread)
@@ -1746,18 +1750,20 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThre
 
     PR_Free(thread->name);
     nameLen = strlen(name);
     thread->name = (char *)PR_Malloc(nameLen + 1);
     if (!thread->name)
         return PR_FAILURE;
     memcpy(thread->name, name, nameLen + 1);
 
-#if defined(OPENBSD) || defined(FREEBSD)
-    result = pthread_set_name_np(thread->id, name);
+#if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY)
+    pthread_set_name_np(thread->id, name);
+#elif defined(NETBSD)
+    result = pthread_setname_np(thread->id, "%s", (void *)name);
 #else /* not BSD */
     /*
      * On OSX, pthread_setname_np is only available in 10.6 or later, so test
      * for it at runtime.  It also may not be available on all linux distros.
      */
 #if defined(DARWIN)
     int (*dynamic_pthread_setname_np)(const char*);
 #else