]> granicus.if.org Git - llvm/commitdiff
Detect the existence of pthread_{s,g}etname_np in libpthread on Linux
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 3 Mar 2017 21:53:12 +0000 (21:53 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 3 Mar 2017 21:53:12 +0000 (21:53 +0000)
Older Linux distributions may not have those functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296915 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/config-ix.cmake
lib/Support/Unix/Threading.inc

index 42af23d377f391dc74c87a90c7f612f28648a0ea..34c81fa2973d31023faf049cb9bdf841e0a86a89 100755 (executable)
@@ -246,6 +246,14 @@ check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
 if( LLVM_USING_GLIBC )
   add_llvm_definitions( -D_GNU_SOURCE )
 endif()
+# This check requires _GNU_SOURCE
+if(HAVE_LIBPTHREAD)
+  check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
+  check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
+elseif(PTHREAD_IN_LIBC)
+  check_library_exists(c pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
+  check_library_exists(c pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
+endif()
 
 set(headers "sys/types.h")
 
index 2bcf8e5cd5f96144ac55b1b6eca0e1456034387e..6301a674df0544e4ef50d7880ddc9682bfe6835b 100644 (file)
@@ -115,8 +115,10 @@ void llvm::set_thread_name(const Twine &Name) {
   StringRef NameStr = Name.toNullTerminatedStringRef(Storage);
 #if defined(__linux__)
 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
+#if HAVE_PTHREAD_SETNAME_NP
   ::pthread_setname_np(::pthread_self(), NameStr.data());
 #endif
+#endif
 #elif defined(__FreeBSD__)
   ::pthread_set_name_np(::pthread_self(), NameStr.data());
 #elif defined(__NetBSD__)
@@ -173,10 +175,12 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
   Name.append(buf, buf + strlen(buf));
 #elif defined(__linux__)
 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
+#if HAVE_PTHREAD_GETNAME_NP
   constexpr int MAXNAMELEN = 16;
   char Buffer[MAXNAMELEN];
   if (0 == ::pthread_getname_np(::pthread_self(), Buffer, MAXNAMELEN))
     Name.append(Buffer, Buffer + strlen(Buffer));
 #endif
 #endif
+#endif
 }