]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compat: add abstractions for non portable pthread name funcs 9763/head
authorJohn Coyle <dx9err@gmail.com>
Fri, 24 Jun 2016 17:49:42 +0000 (13:49 -0400)
committerJohn Coyle <dx9err@gmail.com>
Mon, 4 Jul 2016 15:19:51 +0000 (11:19 -0400)
Supports GNU, FreeBSD, OSX, and Alpine.

Signed-off-by: John Coyle <dx9err@gmail.com>
CMakeLists.txt
configure.ac
src/client/SyntheticClient.cc
src/common/WorkQueue.cc
src/global/signal_handler.cc
src/include/compat.h
src/include/config-h.in.cmake

index ea937f10cd5d76f2c5fa8c7c7a8f8597e1dae9da..5f549195854231d4b2270b3a14eb28e0cd7e791e 100644 (file)
@@ -86,6 +86,9 @@ CHECK_FUNCTION_EXISTS(name_to_handle_at HAVE_NAME_TO_HANDLE_AT)
 CHECK_FUNCTION_EXISTS(pipe2 HAVE_PIPE2)
 set(CMAKE_REQUIRED_LIBRARIES pthread)
 CHECK_FUNCTION_EXISTS(pthread_spin_init HAVE_PTHREAD_SPINLOCK)
+CHECK_FUNCTION_EXISTS(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
+CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
+CHECK_FUNCTION_EXISTS(pthread_getname_np HAVE_PTHREAD_GETNAME_NP)
 CHECK_FUNCTION_EXISTS(eventfd HAVE_EVENTFD)
 
 CHECK_INCLUDE_FILE_CXX("boost/asio/coroutine.hpp" HAVE_BOOST_ASIO_COROUTINE)
index b83cdf9e4e91e06cb2f8ba053a05869625c76556..0845fcb6b0708cf30253a8e75a2d2d305f723277 100644 (file)
@@ -1145,6 +1145,7 @@ LIBS="$PTHREAD_LIBS $LIBS"
 CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
 AC_CHECK_FUNC([pthread_spin_init],
   [AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [Define if you have pthread_spin_init])])
+AC_CHECK_FUNCS([pthread_getname_np pthread_setname_np pthread_set_name_np])
 LIBS="$saved_LIBS"
 CFLAGS="$saved_CFLAGS"
 
index b2ef93ae30ba5c151eb12c4cf7d970987d3383fe..7e324fdb704acd6472d95cdf3ffce3a7d24a7e20 100644 (file)
@@ -12,6 +12,8 @@
  * 
  */
 
+#include "include/compat.h"
+
 #include <iostream>
 #include <sstream>
 using namespace std;
index 6fc468ab5c12561e1d4635fccd9e432e8820828e..34304915887740af76ca524900f2e8d019f5ba22 100644 (file)
@@ -12,6 +12,8 @@
  * 
  */
 
+#include "include/compat.h"
+
 #include <sstream>
 
 #include "include/types.h"
@@ -95,9 +97,7 @@ void ThreadPool::worker(WorkThread *wt)
   
   std::stringstream ss;
   char name[16] = {0};
-#if !defined(__FreeBSD__)
   pthread_getname_np(pthread_self(), name, sizeof(name));
-#endif
   ss << name << " thread " << name;
   heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
 
@@ -302,9 +302,7 @@ void ShardedThreadPool::shardedthreadpool_worker(uint32_t thread_index)
 
   std::stringstream ss;
   char name[16] = {0};
-#if !defined(__FreeBSD__)
   pthread_getname_np(pthread_self(), name, sizeof(name));
-#endif
   ss << name << " thread " << name;
   heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
 
index a01a78a868ad53064f81e8465575afd238cbc133..5b65065cdc6915767f1c7404f681df7dc2512cc6 100644 (file)
@@ -12,6 +12,8 @@
  *
  */
 
+#include "include/compat.h"
+
 #include "common/BackTrace.h"
 #include "common/debug.h"
 #include "global/pidfile.h"
@@ -90,10 +92,8 @@ static void handle_fatal_signal(int signum)
   // presumably dump core-- will handle it.
   char buf[1024];
   char pthread_name[16] = {0}; //limited by 16B include terminating null byte.
-#if !defined(__FreeBSD__)
   int r = pthread_getname_np(pthread_self(), pthread_name, sizeof(pthread_name));
   (void)r;
-#endif
 #if defined(__sun)
   char message[SIG2STR_MAX];
   sig2str(signum,message);
index 1df098bc42f5ef507d0605a179a53a7c068f6c8f..7dc2833ad6fb10e669a8949bf8a4046c7c3c1916 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef CEPH_COMPAT_H
 #define CEPH_COMPAT_H
 
+#include "acconfig.h"
+
 #if defined(__FreeBSD__)
 
 /* Make sure that ENODATA is defined in the correct way */
@@ -58,8 +60,6 @@
 #endif
 #endif
 
-/* Fix a small name diff */
-#define pthread_setname_np pthread_set_name_np
 /* And include the extra required include file */
 #include <pthread_np.h>
 
 #define MSG_DONTWAIT MSG_NONBLOCK
 #endif
 
+#if defined(HAVE_PTHREAD_SETNAME_NP)
+  #if defined(__APPLE__)
+    #define pthread_setname_np(thread, name) ({ \
+      int __result = 0;                         \
+      if (thread == pthread_self())             \
+        __result = pthread_setname_np(name)     \
+      __result; })
+  #endif
+#elif defined(HAVE_PTHREAD_SET_NAME_NP)
+  /* Fix a small name diff */
+  #define pthread_setname_np pthread_set_name_np
+#else
+  /* compiler warning free success noop */
+  #define pthread_setname_np(thread, name) ({ \
+    int __i = 0;                              \
+    __i; })
+#endif
+
+#if !defined(HAVE_PTHREAD_GETNAME_NP)
+  /* compiler warning free success noop */
+  #define pthread_getname_np(thread, name, len) ({ \
+    if (name != NULL)                              \
+      *name = '\0';                                \
+    0; })
+#endif
+
 #endif /* !CEPH_COMPAT_H */
index 0292f7e85323450a894aa63cee8caeaa2c6959e9..1d6bc706f68e70f42bd959144663b4ac0a0889ca 100644 (file)
 /* Version number of package */
 #cmakedefine VERSION "@VERSION@"
 
+/* Defined if pthread_setname_np() is available */
+#cmakedefine HAVE_PTHREAD_SETNAME_NP 1
+
+/* Defined if pthread_set_name_np() is available */
+#cmakedefine HAVE_PTHREAD_SET_NAME_NP
+
+/* Defined if pthread_getname_np() is available */
+#cmakedefine HAVE_PTHREAD_GETNAME_NP 1
+
 #endif /* CONFIG_H */