From a78bf7b9144ed3db8e798124595f48fc75231cce Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 29 Jan 2010 22:59:09 +0000 Subject: Replace PeriodicTimer with ClusterTimer, which inherits from Timer. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@904656 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/Timer.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/sys/Timer.cpp') diff --git a/cpp/src/qpid/sys/Timer.cpp b/cpp/src/qpid/sys/Timer.cpp index c18fd93538..fcd58b187f 100644 --- a/cpp/src/qpid/sys/Timer.cpp +++ b/cpp/src/qpid/sys/Timer.cpp @@ -30,14 +30,16 @@ using std::max; namespace qpid { namespace sys { -TimerTask::TimerTask(Duration timeout) : +TimerTask::TimerTask(Duration timeout, const std::string& n) : + name(n), sortTime(AbsTime::FarFuture()), period(timeout), nextFireTime(AbsTime::now(), timeout), cancelled(false) {} -TimerTask::TimerTask(AbsTime time) : +TimerTask::TimerTask(AbsTime time, const std::string& n) : + name(n), sortTime(AbsTime::FarFuture()), period(0), nextFireTime(time), @@ -102,13 +104,15 @@ void Timer::run() { ScopedLock l(t->callbackLock); if (t->cancelled) { + drop(t); if (delay > 500 * TIME_MSEC) { - QPID_LOG(debug, "cancelled Timer woken up " << delay / TIME_MSEC << "ms late"); + QPID_LOG(debug, "cancelled Timer woken up " << delay / TIME_MSEC + << "ms late"); } continue; } else if(Duration(t->nextFireTime, start) >= 0) { Monitor::ScopedUnlock u(monitor); - t->fireTask(); + fire(t); // Warn on callback overrun AbsTime end(AbsTime::now()); Duration overrun(tasks.top()->nextFireTime, end); @@ -169,6 +173,14 @@ void Timer::stop() runner.join(); } +// Allow subclasses to override behavior when firing a task. +void Timer::fire(boost::intrusive_ptr t) { + t->fireTask(); +} + +// Provided for subclasses: called when a task is droped. +void Timer::drop(boost::intrusive_ptr) {} + bool operator<(const intrusive_ptr& a, const intrusive_ptr& b) { -- cgit v1.2.1