From: Yehuda Sadeh Date: Wed, 28 May 2014 00:09:50 +0000 (-0700) Subject: timer: fix RWTimer shutdown X-Git-Tag: v0.86~213^2~95 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=452dc9e64fd4b6fe9b3ceece2f2281e4640148e6;p=ceph.git timer: fix RWTimer shutdown Signed-off-by: Yehuda Sadeh --- diff --git a/src/common/Timer.cc b/src/common/Timer.cc index 7d04823f787..e64d504557e 100644 --- a/src/common/Timer.cc +++ b/src/common/Timer.cc @@ -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; diff --git a/src/common/Timer.h b/src/common/Timer.h index 11333998f50..374bd4ad4f4 100644 --- a/src/common/Timer.h +++ b/src/common/Timer.h @@ -115,7 +115,7 @@ class RWTimer std::multimap schedule; std::map::iterator> events; - bool stopping; + atomic_t stopping; void dump(const char *caller = 0) const;