[PATCH] D30526: [Support] Add functions to get and set thread name.

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 23:59:20 PST 2017


davide added inline comments.


================
Comment at: llvm/lib/Support/Threading.cpp:43-50
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#if defined(__FreeBSD__)
+#include <pthread_np.h>
----------------
The inner `#if defined(__FreeBSD__) is redundant, maybe? (as you're doing the same outside)


================
Comment at: llvm/lib/Support/Threading.cpp:158-163
+#if defined(__linux__)
+#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
+  ::pthread_setname_np(::pthread_self(), NameStr.c_str());
+#endif
+#elif defined(__FreeBSD__)
+  ::pthread_set_name_np(::pthread_self(), NameStr.c_str());
----------------
davide wrote:
> I'm wondering if there's a way to avoid this ugly `#ifdef` dance.
Maybe you can merge these two cases?


================
Comment at: llvm/lib/Support/Threading.cpp:164-166
+#elif defined(__NetBSD__)
+  ::pthread_setname_np(::pthread_self(), "%s",
+                       const_cast<char *>(NameStr.c_str()));
----------------
Amazing how 4 operating systems define pretty much the same call with slightly different variants.


https://reviews.llvm.org/D30526





More information about the llvm-commits mailing list