From 11914dc351c05ce8a33ff71ba484677916e7fe36 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 10 Jul 2017 15:31:16 +0800 Subject: [PATCH] common/Timer: return false if event not added Signed-off-by: Kefu Chai --- src/common/Timer.cc | 9 +++++---- src/common/Timer.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/common/Timer.cc b/src/common/Timer.cc index 82e090148f3..f211a6f8ff8 100644 --- a/src/common/Timer.cc +++ b/src/common/Timer.cc @@ -114,22 +114,23 @@ void SafeTimer::timer_thread() lock.Unlock(); } -void SafeTimer::add_event_after(double seconds, Context *callback) +bool SafeTimer::add_event_after(double seconds, Context *callback) { assert(lock.is_locked()); utime_t when = ceph_clock_now(); when += seconds; - add_event_at(when, callback); + return add_event_at(when, callback); } -void SafeTimer::add_event_at(utime_t when, Context *callback) +bool SafeTimer::add_event_at(utime_t when, Context *callback) { assert(lock.is_locked()); ldout(cct,10) << __func__ << " " << when << " -> " << callback << dendl; if (stopping) { ldout(cct,5) << __func__ << " already shutdown, event not added" << dendl; delete callback; + return false; } scheduled_map_t::value_type s_val(when, callback); scheduled_map_t::iterator i = schedule.insert(s_val); @@ -144,7 +145,7 @@ void SafeTimer::add_event_at(utime_t when, Context *callback) * adjust our timeout. */ if (i == schedule.begin()) cond.Signal(); - + return true; } bool SafeTimer::cancel_event(Context *callback) diff --git a/src/common/Timer.h b/src/common/Timer.h index 078a172b25b..861b239ca32 100644 --- a/src/common/Timer.h +++ b/src/common/Timer.h @@ -70,8 +70,8 @@ public: /* Schedule an event in the future * Call with the event_lock LOCKED */ - void add_event_after(double seconds, Context *callback); - void add_event_at(utime_t when, Context *callback); + bool add_event_after(double seconds, Context *callback); + bool add_event_at(utime_t when, Context *callback); /* Cancel an event. * Call with the event_lock LOCKED -- 2.39.5