]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async/Event: change to use pthread_t to indicate whether the same thread
authorHaomai Wang <haomai@xsky.com>
Tue, 28 Jun 2016 04:11:13 +0000 (12:11 +0800)
committerHaomai Wang <haomai@xsky.com>
Wed, 29 Jun 2016 04:14:29 +0000 (12:14 +0800)
thread_local has problem in TmapMigratePP.DataScan case that it will be
assigned to zero unexpectedly.

pthread_t is much cheaper than gettid since it's a library implementation.

Signed-off-by: Haomai Wang <haomai@xsky.com>
src/msg/async/Event.cc
src/msg/async/Event.h

index 752fcb5371d497afe7f837a18439a0f86bb8f419..5e436d5a20c7b9305bf7126ce6b3ac42064a93c3 100644 (file)
@@ -59,8 +59,6 @@ ostream& EventCenter::_event_prefix(std::ostream *_dout)
                 << " time_id=" << time_event_next_id << ").";
 }
 
-thread_local EventCenter* local_center = nullptr;
-
 int EventCenter::init(int n, unsigned i)
 {
   // can't init multi times
@@ -145,8 +143,9 @@ void EventCenter::set_owner()
   cct->lookup_or_create_singleton_object<EventCenter::AssociatedCenters>(
       global_centers, "AsyncMessenger::EventCenter::global_center");
   assert(global_centers && !global_centers->centers[idx]);
-  global_centers->centers[idx] = local_center = this;
-  ldout(cct, 1) << __func__ << " idx=" << idx << " local_center=" << local_center << dendl;
+  global_centers->centers[idx] = this;
+  owner = pthread_self();
+  ldout(cct, 1) << __func__ << " idx=" << idx << " owner=" << owner << dendl;
 }
 
 int EventCenter::create_file_event(int fd, int mask, EventCallbackRef ctxt)
index 27bbca5b7155b0136527c5b0c10934d220056ec0..7375e6d9fa501088be954380f7ddf09c609730c8 100644 (file)
@@ -80,12 +80,6 @@ class EventDriver {
   virtual int resize_events(int newsize) = 0;
 };
 
-extern thread_local EventCenter* local_center;
-
-inline EventCenter* center() {
-  return local_center;
-}
-
 /*
  * EventCenter maintain a set of file descriptor and handle registered events.
  */
@@ -119,6 +113,7 @@ class EventCenter {
   CephContext *cct;
   int nevent;
   // Used only to external event
+  pthread_t owner;
   std::mutex external_lock, file_lock;;
   std::atomic_ulong external_num_events;
   deque<EventCallbackRef> external_events;
@@ -169,7 +164,7 @@ class EventCenter {
   // Used by external thread
   void dispatch_event_external(EventCallbackRef e);
   inline bool in_thread() const {
-    return local_center == this;
+    return pthread_equal(pthread_self(), owner);
   }
 
  private: