]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
timer: fix RWTimer shutdown
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 28 May 2014 00:09:50 +0000 (17:09 -0700)
committerJohn Spray <john.spray@redhat.com>
Mon, 25 Aug 2014 00:33:59 +0000 (01:33 +0100)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/common/Timer.cc
src/common/Timer.h

index 7d04823f787219035f078398877a5cf3b979c7c5..e64d504557e0f6831696a2390e9f4cfb51064d75 100644 (file)
@@ -205,8 +205,7 @@ public:
 RWTimer::RWTimer(CephContext *cct_, RWLock &rwl, bool safe_callbacks)
   : cct(cct_), rwlock(rwl), lock("RWTimer::lock"),
     safe_callbacks(safe_callbacks),
-    thread(NULL),
-    stopping(false)
+    thread(NULL)
 {
 }
 
@@ -228,7 +227,7 @@ void RWTimer::shutdown()
   if (thread) {
     assert(rwlock.is_locked());
     cancel_all_events();
-    stopping = true;
+    stopping.set(1);
     lock.Lock();
     cond.Signal();
     lock.Unlock();
@@ -244,7 +243,7 @@ void RWTimer::timer_thread()
   ldout(cct,10) << "timer_thread starting" << dendl;
   lock.Lock();
 
-  while (!stopping) {
+  while (!stopping.read()) {
     utime_t now = ceph_clock_now(cct);
 
     while (!schedule.empty()) {
@@ -283,9 +282,16 @@ void RWTimer::timer_thread()
       cond.WaitUntil(lock, schedule.begin()->first);
 
     lock.Unlock();
+
+    ldout(cct,20) << "timer_thread awake" << dendl;
+
+    if (stopping.read()) {
+      ldout(cct,10) << "timer_thread exiting" << dendl;
+      return;
+    }
+
     rwlock.get_write();
     lock.Lock();
-    ldout(cct,20) << "timer_thread awake" << dendl;
   }
   lock.Unlock();
   ldout(cct,10) << "timer_thread exiting" << dendl;
index 11333998f50d025b0ee5a105b8632b888e6fa005..374bd4ad4f4497d0372ca58b271e81b3cfe098dd 100644 (file)
@@ -115,7 +115,7 @@ class RWTimer
 
   std::multimap<utime_t, Context*> schedule;
   std::map<Context*, std::multimap<utime_t, Context*>::iterator> events;
-  bool stopping;
+  atomic_t stopping;
 
   void dump(const char *caller = 0) const;