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)
{
}
if (thread) {
assert(rwlock.is_locked());
cancel_all_events();
- stopping = true;
+ stopping.set(1);
lock.Lock();
cond.Signal();
lock.Unlock();
ldout(cct,10) << "timer_thread starting" << dendl;
lock.Lock();
- while (!stopping) {
+ while (!stopping.read()) {
utime_t now = ceph_clock_now(cct);
while (!schedule.empty()) {
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;
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;