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