[PATCH] D30526: [Support] Add functions to get and set thread name.
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 13:49:04 PST 2017
zturner 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>
----------------
davide wrote:
> The inner `#if defined(__FreeBSD__) is redundant, maybe? (as you're doing the same outside)
I don't think `pthread_np.h` exists on the other flavors of BSD though right? (I actually dont' know, but this is how I translated the code from LLDB. NetBSD and FreeBSD Kernel were not including these headers.
================
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:
> davide wrote:
> > I'm wondering if there's a way to avoid this ugly `#ifdef` dance.
> Maybe you can merge these two cases?
The name of the function is slightly different though. For FreeBSD there is an extra underscore. So I have to paper over that difference with a `#define` somewhere, even if not here.
================
Comment at: llvm/lib/Support/Threading.cpp:164-166
+#elif defined(__NetBSD__)
+ ::pthread_setname_np(::pthread_self(), "%s",
+ const_cast<char *>(NameStr.c_str()));
----------------
davide wrote:
> Amazing how 4 operating systems define pretty much the same call with slightly different variants.
I know right? Very annoying :-/
https://reviews.llvm.org/D30526
More information about the llvm-commits
mailing list