[llvm] r296915 - Detect the existence of pthread_{s, g}etname_np in libpthread on Linux
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 13:53:12 PST 2017
Author: kparzysz
Date: Fri Mar 3 15:53:12 2017
New Revision: 296915
URL: http://llvm.org/viewvc/llvm-project?rev=296915&view=rev
Log:
Detect the existence of pthread_{s,g}etname_np in libpthread on Linux
Older Linux distributions may not have those functions.
Modified:
llvm/trunk/cmake/config-ix.cmake
llvm/trunk/lib/Support/Unix/Threading.inc
Modified: llvm/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=296915&r1=296914&r2=296915&view=diff
==============================================================================
--- llvm/trunk/cmake/config-ix.cmake (original)
+++ llvm/trunk/cmake/config-ix.cmake Fri Mar 3 15:53:12 2017
@@ -246,6 +246,14 @@ check_symbol_exists(__GLIBC__ stdio.h LL
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")
Modified: llvm/trunk/lib/Support/Unix/Threading.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Threading.inc?rev=296915&r1=296914&r2=296915&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Threading.inc (original)
+++ llvm/trunk/lib/Support/Unix/Threading.inc Fri Mar 3 15:53:12 2017
@@ -115,8 +115,10 @@ void llvm::set_thread_name(const Twine &
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(SmallVectorIm
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
}
More information about the llvm-commits
mailing list