1From 0dfb289a3b362b082ac3608d887e42f09dadc0d2 Mon Sep 17 00:00:00 2001 2From: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 3Date: Mon, 31 Dec 2018 16:22:07 +0100 4Subject: [PATCH] Properly detect the availability of pthread_setname_np() 5 6This commit adds a CMake check for the availability of 7pthread_setname_np(), and only uses it on Linux when available. 8 9Indeed, some C libraries, such as uClibc, do not provide this 10non-POSIX function in all cases. 11 12Upstream: https://github.com/grpc/grpc/pull/17610 13Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 14--- 15 CMakeLists.txt | 6 ++++++ 16 include/grpc/impl/codegen/port_platform.h | 2 ++ 17 2 files changed, 8 insertions(+) 18 19diff --git a/CMakeLists.txt b/CMakeLists.txt 20index 45c2fcb..0b2be4f 100644 21--- a/CMakeLists.txt 22+++ b/CMakeLists.txt 23@@ -208,6 +208,12 @@ if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) 24 endif() 25 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") 26 27+include(CheckSymbolExists) 28+check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP) 29+if (HAVE_PTHREAD_SETNAME_NP) 30+ add_definitions(-DHAVE_PTHREAD_SETNAME_NP) 31+endif () 32+ 33 if(MSVC) 34 include(cmake/msvc_static_runtime.cmake) 35 add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) 36diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h 37index 4f213ff..55ecd9d 100644 38--- a/include/grpc/impl/codegen/port_platform.h 39+++ b/include/grpc/impl/codegen/port_platform.h 40@@ -168,7 +168,9 @@ 41 #endif /* _LP64 */ 42 #ifdef __GLIBC__ 43 #define GPR_POSIX_CRASH_HANDLER 1 44+#if defined(HAVE_PTHREAD_SETNAME_NP) 45 #define GPR_LINUX_PTHREAD_NAME 1 46+#endif /* HAVE_PTHREAD_SETNAME_NP */ 47 #include <linux/version.h> 48 #else /* musl libc */ 49 #define GPR_MUSL_LIBC_COMPAT 1 50-- 512.26.63 52