Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

brad0
Copy link
Contributor

@brad0 brad0 commented Aug 29, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2024

@llvm/pr-subscribers-llvm-support

Author: Brad Smith (brad0)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/106486.diff

1 Files Affected:

  • (modified) llvm/lib/Support/Unix/Threading.inc (+3-13)
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) {

@brad0 brad0 requested a review from TNorthover September 1, 2024 03:59
@brad0 brad0 merged commit 647f892 into llvm:main Sep 2, 2024
10 checks passed
@brad0 brad0 deleted the llvm_threading_setname_simplify branch September 3, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants