[llvm] [llvm][Support] Simplify HAVE_PTHREAD_GETNAME/SETNAME_NP handling. NFCI (PR #106486)

Brad Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 21:45:46 PDT 2024


https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/106486

None

>From 77c4a1a23e11f6ba60980638e9dda7834309502d Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Thu, 29 Aug 2024 00:37:13 -0400
Subject: [PATCH] [llvm][Support] Simplify HAVE_PTHREAD_GETNAME/SETNAME_NP
 handling. NFCI

---
 llvm/lib/Support/Unix/Threading.inc | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 839c00c5ebbf96..6ba6395e6b8d63 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -141,12 +141,8 @@ static constexpr uint32_t get_max_thread_name_length_impl() {
   return PTHREAD_MAX_NAMELEN_NP;
 #elif defined(__APPLE__)
   return 64;
-#elif defined(__linux__)
-#if HAVE_PTHREAD_SETNAME_NP
+#elif defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
   return 16;
-#else
-  return 0;
-#endif
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
   return 16;
 #elif defined(__OpenBSD__)
@@ -174,12 +170,8 @@ void llvm::set_thread_name(const Twine &Name) {
   if (get_max_thread_name_length() > 0)
     NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
   (void)NameStr;
-#if defined(__linux__)
-#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
-#if HAVE_PTHREAD_SETNAME_NP
+#if defined(__linux__) && HAVE_PTHREAD_SETNAME_NP
   ::pthread_setname_np(::pthread_self(), NameStr.data());
-#endif
-#endif
 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
   ::pthread_set_name_np(::pthread_self(), NameStr.data());
 #elif defined(__NetBSD__)
@@ -241,14 +233,12 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
   ::pthread_get_name_np(::pthread_self(), buf, len);
 
   Name.append(buf, buf + strlen(buf));
-#elif defined(__linux__)
-#if HAVE_PTHREAD_GETNAME_NP
+#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
   constexpr uint32_t len = get_max_thread_name_length_impl();
   char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
   if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
     Name.append(Buffer, Buffer + strlen(Buffer));
 #endif
-#endif
 }
 
 SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {



More information about the llvm-commits mailing list