diff options
author | Gordon Sim <gsim@apache.org> | 2009-07-14 09:58:51 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2009-07-14 09:58:51 +0000 |
commit | 9458e8ed680357e678e90e2899f9f269566bcc30 (patch) | |
tree | b43683bc586d0d7efa383c2329e04bdbd1f43938 /qpid/cpp/src | |
parent | a7b255e65d01404979a0276c554327eaebedcb56 (diff) | |
download | qpid-python-9458e8ed680357e678e90e2899f9f269566bcc30.tar.gz |
Reapplied r793120
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@793832 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r-- | qpid/cpp/src/qpid/sys/Timer.cpp | 12 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/sys/Timer.h | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/sys/Timer.cpp b/qpid/cpp/src/qpid/sys/Timer.cpp index 6967d812ae..fd42d7d62e 100644 --- a/qpid/cpp/src/qpid/sys/Timer.cpp +++ b/qpid/cpp/src/qpid/sys/Timer.cpp @@ -30,12 +30,14 @@ namespace qpid { namespace sys { TimerTask::TimerTask(Duration timeout) : + sortTime(AbsTime::FarFuture()), period(timeout), nextFireTime(AbsTime::now(), timeout), cancelled(false) {} TimerTask::TimerTask(AbsTime time) : + sortTime(AbsTime::FarFuture()), period(0), nextFireTime(time), cancelled(false) @@ -60,7 +62,7 @@ void TimerTask::setupNextFire() { } // Only allow tasks to be delayed -void TimerTask::restart() { nextFireTime = AbsTime(AbsTime::now(), period); } +void TimerTask::restart() { nextFireTime = max(nextFireTime, AbsTime(AbsTime::now(), period)); } void TimerTask::delayTill(AbsTime time) { period = 0; nextFireTime = max(nextFireTime, time); } void TimerTask::cancel() { @@ -91,7 +93,7 @@ void Timer::run() tasks.pop(); { ScopedLock<Mutex> l(t->callbackLock); - if (t->isCancelled()) { + if (t->cancelled) { continue; } else if(t->readyToFire()) { Monitor::ScopedUnlock u(monitor); @@ -100,6 +102,9 @@ void Timer::run() } else { // If the timer was adjusted into the future it might no longer // be the next event, so push and then get top to make sure + // You can only push events into the future + assert(!(t->nextFireTime < t->sortTime)); + t->sortTime = t->nextFireTime; tasks.push(t); } } @@ -111,6 +116,7 @@ void Timer::run() void Timer::add(intrusive_ptr<TimerTask> task) { Monitor::ScopedLock l(monitor); + task->sortTime = task->nextFireTime; tasks.push(task); monitor.notify(); } @@ -139,7 +145,7 @@ bool operator<(const intrusive_ptr<TimerTask>& a, const intrusive_ptr<TimerTask>& b) { // Lower priority if time is later - return a.get() && b.get() && a->nextFireTime > b->nextFireTime; + return a.get() && b.get() && a->sortTime > b->sortTime; } }} diff --git a/qpid/cpp/src/qpid/sys/Timer.h b/qpid/cpp/src/qpid/sys/Timer.h index c1f0ae89fc..fc7491d5ed 100644 --- a/qpid/cpp/src/qpid/sys/Timer.h +++ b/qpid/cpp/src/qpid/sys/Timer.h @@ -42,6 +42,7 @@ class TimerTask : public RefCounted { friend bool operator<(const boost::intrusive_ptr<TimerTask>&, const boost::intrusive_ptr<TimerTask>&); + AbsTime sortTime; Duration period; AbsTime nextFireTime; Mutex callbackLock; |