0001-Properly-detect-the-availability-of-pthread_setname_.patch 2.3 KB

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