summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2009-06-08 14:34:52 +0000
committerAndrew Stitcher <astitcher@apache.org>2009-06-08 14:34:52 +0000
commit312d8e131e1951ebcd9b1d48bf318b112d4b7b33 (patch)
tree5bc4483934a8a719136e4502f28d270a43ed58cb /cpp
parent4274737d8315848edc4fa0ccb534482202ce5658 (diff)
downloadqpid-python-312d8e131e1951ebcd9b1d48bf318b112d4b7b33.tar.gz
Fixed broker Timer implementation so that you can correctly
change the expiry time of a queued TimerTask. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@782650 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/qpid/broker/Timer.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/cpp/src/qpid/broker/Timer.cpp b/cpp/src/qpid/broker/Timer.cpp
index 46bbdbb574..53a1597deb 100644
--- a/cpp/src/qpid/broker/Timer.cpp
+++ b/cpp/src/qpid/broker/Timer.cpp
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -41,12 +41,12 @@ void TimerTask::reset() { time = AbsTime(AbsTime::now(), duration); }
void TimerTask::cancel() { cancelled = true; }
bool TimerTask::isCancelled() const { return cancelled; }
-Timer::Timer() : active(false)
+Timer::Timer() : active(false)
{
start();
}
-Timer::~Timer()
+Timer::~Timer()
{
stop();
}
@@ -59,14 +59,16 @@ void Timer::run()
monitor.wait();
} else {
intrusive_ptr<TimerTask> t = tasks.top();
+ tasks.pop();
if (t->isCancelled()) {
- tasks.pop();
} else if(t->time < AbsTime::now()) {
- tasks.pop();
Monitor::ScopedUnlock u(monitor);
t->fire();
} else {
- monitor.wait(t->time);
+ // 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
+ tasks.push(t);
+ monitor.wait(tasks.top()->time);
}
}
}