summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/Timer.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2010-01-29 22:59:09 +0000
committerAlan Conway <aconway@apache.org>2010-01-29 22:59:09 +0000
commita78bf7b9144ed3db8e798124595f48fc75231cce (patch)
treeb7284043fe639a2c6a880fc33836ce0b51d21b7e /cpp/src/qpid/sys/Timer.cpp
parent726b23f43478a85b961365e4de3a9302a261f6b3 (diff)
downloadqpid-python-a78bf7b9144ed3db8e798124595f48fc75231cce.tar.gz
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
Diffstat (limited to 'cpp/src/qpid/sys/Timer.cpp')
-rw-r--r--cpp/src/qpid/sys/Timer.cpp20
1 files changed, 16 insertions, 4 deletions
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<Mutex> 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<TimerTask> t) {
+ t->fireTask();
+}
+
+// Provided for subclasses: called when a task is droped.
+void Timer::drop(boost::intrusive_ptr<TimerTask>) {}
+
bool operator<(const intrusive_ptr<TimerTask>& a,
const intrusive_ptr<TimerTask>& b)
{