]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compat: define ceph_pthread_{set,get}name()
authorYan, Zheng <zyan@redhat.com>
Tue, 12 Jul 2016 02:28:59 +0000 (10:28 +0800)
committerYan, Zheng <zyan@redhat.com>
Mon, 18 Jul 2016 07:01:32 +0000 (15:01 +0800)
pthread_setname_np() exists on OSX, but it only accepts a sinlge
argument. Defining a two parameters version pthread_setname_np()
does not work.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/SyntheticClient.cc
src/common/Thread.cc
src/common/WorkQueue.cc
src/common/obj_bencher.cc
src/global/signal_handler.cc
src/include/compat.h

index f99c5ac7d5604d4136d7b31f9ec5199698c4dbe3..322026751133f8be592694a9d51d23c10b5691ff 100644 (file)
@@ -936,7 +936,7 @@ int SyntheticClient::start_thread()
 
   pthread_create(&thread_id, NULL, synthetic_client_thread_entry, this);
   assert(thread_id);
-  pthread_setname_np(thread_id, "client");
+  ceph_pthread_setname(thread_id, "client");
   return 0;
 }
 
index 16591157d113e4102c17fdd8ddaacc21aa807356..3e8d3434624ff83e59b9d82788c682c52a9b223a 100644 (file)
@@ -85,7 +85,7 @@ void *Thread::entry_wrapper()
   if (pid && cpuid >= 0)
     _set_affinity(cpuid);
 
-  pthread_setname_np(pthread_self(), thread_name);
+  ceph_pthread_setname(pthread_self(), thread_name);
   return entry();
 }
 
index 5cdaed75cfa8d359ad9104a6669e2c12e3e9d625..f37d125b5d720c3a54493eda6a2bb9fe90f0917d 100644 (file)
@@ -97,7 +97,7 @@ void ThreadPool::worker(WorkThread *wt)
   
   std::stringstream ss;
   char name[16] = {0};
-  pthread_getname_np(pthread_self(), name, sizeof(name));
+  ceph_pthread_getname(pthread_self(), name, sizeof(name));
   ss << name << " thread " << name;
   heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
 
@@ -312,7 +312,7 @@ void ShardedThreadPool::shardedthreadpool_worker(uint32_t thread_index)
 
   std::stringstream ss;
   char name[16] = {0};
-  pthread_getname_np(pthread_self(), name, sizeof(name));
+  ceph_pthread_getname(pthread_self(), name, sizeof(name));
   ss << name << " thread " << name;
   heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
 
index 1ffa8ce60022518cdadcc983ed17285ff17dda95..28520fc11c8832e13af8ec7191aae1aa3408e8ec 100644 (file)
@@ -437,7 +437,7 @@ int ObjBencher::write_bench(int secondsToRun,
   pthread_t print_thread;
 
   pthread_create(&print_thread, NULL, ObjBencher::status_printer, (void *)this);
-  pthread_setname_np(print_thread, "write_stat");
+  ceph_pthread_setname(print_thread, "write_stat");
   lock.Lock();
   data.finished = 0;
   data.start_time = ceph_clock_now(cct);
@@ -673,7 +673,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
 
   pthread_t print_thread;
   pthread_create(&print_thread, NULL, status_printer, (void *)this);
-  pthread_setname_np(print_thread, "seq_read_stat");
+  ceph_pthread_setname(print_thread, "seq_read_stat");
 
   utime_t finish_time = data.start_time + time_to_run;
   //start initial reads
@@ -902,7 +902,7 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
 
   pthread_t print_thread;
   pthread_create(&print_thread, NULL, status_printer, (void *)this);
-  pthread_setname_np(print_thread, "rand_read_stat");
+  ceph_pthread_setname(print_thread, "rand_read_stat");
 
   utime_t finish_time = data.start_time + time_to_run;
   //start initial reads
index f1b32c92aec6d91a4bb2c04e4d803962049ce523..7c91e8507270d8eff9f7749a43a070e3d042a8e7 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "include/compat.h"
+#include "pthread.h"
 
 #include "common/BackTrace.h"
 #include "common/debug.h"
@@ -92,7 +93,7 @@ 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.
-  int r = pthread_getname_np(pthread_self(), pthread_name, sizeof(pthread_name));
+  int r = ceph_pthread_getname(pthread_self(), pthread_name, sizeof(pthread_name));
   (void)r;
 #if defined(__sun)
   char message[SIG2STR_MAX];
index df9c6be43c5d97f39658fc4e2971cf73bd661a56..2035000b1eb34967a5effd32ffb8c894fedbf609 100644 (file)
 
 #if defined(HAVE_PTHREAD_SETNAME_NP)
   #if defined(__APPLE__)
-    #define pthread_setname_np(thread, name) ({ \
+    #define ceph_pthread_setname(thread, name) ({ \
       int __result = 0;                         \
       if (thread == pthread_self())             \
-        __result = pthread_setname_np(name)     \
+        __result = pthread_setname_np(name);    \
       __result; })
+  #else
+    #define ceph_pthread_setname pthread_setname_np
   #endif
 #elif defined(HAVE_PTHREAD_SET_NAME_NP)
   /* Fix a small name diff */
-  #define pthread_setname_np pthread_set_name_np
+  #define ceph_pthread_setname pthread_set_name_np
 #else
   /* compiler warning free success noop */
-  #define pthread_setname_np(thread, name) ({ \
+  #define ceph_pthread_setname(thread, name) ({ \
     int __i = 0;                              \
     __i; })
 #endif
 
-#if !defined(HAVE_PTHREAD_GETNAME_NP)
+#if defined(HAVE_PTHREAD_GETNAME_NP)
+  #define ceph_pthread_getname pthread_getname_np
+#else
   /* compiler warning free success noop */
-  #define pthread_getname_np(thread, name, len) ({ \
+  #define ceph_pthread_getname(thread, name, len) ({ \
     if (name != NULL)                              \
       *name = '\0';                                \
     0; })