# include <mach/mach.h>
#elif defined(OS_NETBSD)
# include <lwp.h>
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
# include <sys/syscall.h>
# include <sys/prctl.h>
#endif
# include <unistd.h>
#endif
-#if defined(OS_BSD) && !defined(OS_NETBSD) && !defined(__GLIBC__)
+#if defined(OS_BSD) && !defined(OS_NETBSD) && !defined(__GLIBC__) && !defined(__FreeBSD_kernel__)
# include <pthread_np.h>
#endif
// also sets the thread name on the PRThread wrapper, and allows us to
// retrieve it using PR_GetThreadName.
NS_SetCurrentThreadName(name);
+
+ // http://0pointer.de/blog/projects/name-your-threads.html
+ // Set the name for the LWP (which gets truncated to 15 characters).
+ // Note that glibc also has a 'pthread_setname_np' api, but it may not be
+ // available everywhere and it's only benefit over using prctl directly is
+ // that it can set the name of threads other than the current thread.
+#if defined(OS_LINUX) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
+ prctl(PR_SET_NAME, reinterpret_cast<uintptr_t>(name), 0, 0, 0);
+#elif defined(OS_NETBSD)
+ pthread_setname_np(pthread_self(), "%s", (void *)name);
+#elif defined(OS_BSD) && !defined(__GLIBC__)
+ pthread_set_name_np(pthread_self(), name);
+#elif defined(OS_SOLARIS)
+ pthread_setname_np(pthread_self(), name);
+#else
+#endif
}
#endif // !OS_MACOSX