diff options
author | Alan Conway <aconway@apache.org> | 2007-12-06 18:22:17 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-12-06 18:22:17 +0000 |
commit | 430e644a4a647c256ae51682d7230c35d954073e (patch) | |
tree | ef03ef6d4f1e1d7451bf26b943a325e425ef2b58 /cpp/src/qpid/broker/Timer.cpp | |
parent | 8a3e8a01188a500401196601d78ecf146ab8ba66 (diff) | |
download | qpid-python-430e644a4a647c256ae51682d7230c35d954073e.tar.gz |
Removed redundant TimerA, use intrusive_ptr for Timer.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@601803 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/Timer.cpp')
-rw-r--r-- | cpp/src/qpid/broker/Timer.cpp | 100 |
1 files changed, 11 insertions, 89 deletions
diff --git a/cpp/src/qpid/broker/Timer.cpp b/cpp/src/qpid/broker/Timer.cpp index 653e1dffd1..28b1aa56d7 100644 --- a/cpp/src/qpid/broker/Timer.cpp +++ b/cpp/src/qpid/broker/Timer.cpp @@ -27,9 +27,14 @@ using qpid::sys::Monitor; using qpid::sys::Thread; using namespace qpid::broker; -TimerTask::TimerTask(Duration timeout) : duration(timeout), time(AbsTime::now(), timeout), cancelled(false) {} -TimerTask::TimerTask(AbsTime _time) : duration(0), time(_time), cancelled(false) {} +TimerTask::TimerTask(Duration timeout) : + duration(timeout), time(AbsTime::now(), timeout), cancelled(false) {} + +TimerTask::TimerTask(AbsTime _time) : + duration(0), time(_time), cancelled(false) {} + TimerTask::~TimerTask(){} + void TimerTask::reset() { time.reset(AbsTime::now(), duration); } Timer::Timer() : active(false) @@ -49,7 +54,7 @@ void Timer::run() if (tasks.empty()) { monitor.wait(); } else { - TimerTask::shared_ptr t = tasks.top(); + intrusive_ptr<TimerTask> t = tasks.top(); if (t->cancelled) { tasks.pop(); } else if(t->time < AbsTime::now()) { @@ -62,7 +67,7 @@ void Timer::run() } } -void Timer::add(TimerTask::shared_ptr task) +void Timer::add(intrusive_ptr<TimerTask> task) { Monitor::ScopedLock l(monitor); tasks.push(task); @@ -93,92 +98,9 @@ void Timer::signalStop() } } -bool Later::operator()(const TimerTask::shared_ptr& a, const TimerTask::shared_ptr& b) const +bool Later::operator()(const intrusive_ptr<TimerTask>& a, + const intrusive_ptr<TimerTask>& b) const { return a.get() && b.get() && a->time > b->time; } -bool LaterA::operator()(const TimerTaskA::intrusive_ptr& a, const TimerTaskA::intrusive_ptr& b) const -{ - return a.get() && b.get() && a->time > b->time; -} - -TimerA::TimerA(): active(false) -{ - start(); -} - -TimerA::~TimerA() -{ - stop(); -} - -void TimerA::run() -{ - Monitor::ScopedLock l(monitor); - while(active){ - if (itasks.empty()) { - monitor.wait(); - } else { - TimerTaskA::intrusive_ptr t = itasks.top(); - if (t->cancelled) { - itasks.pop(); - } else if(t->time < AbsTime::now()) { - itasks.pop(); - t->fire(); - } else { - monitor.wait(t->time); - } - } - } -// ::run(); -} - -TimerTaskA::TimerTaskA(qpid::sys::Duration timeout): TimerTask(timeout), ref_cnt(0) {} -TimerTaskA::TimerTaskA(qpid::sys::AbsTime time): TimerTask(time), ref_cnt(0) {} -TimerTaskA::~TimerTaskA() {} - - -void TimerA::add(TimerTaskA::intrusive_ptr& task) -{ - Monitor::ScopedLock l(monitor); - itasks.push(task); - monitor.notify(); -} - -void TimerA::start() -{ - Monitor::ScopedLock l(monitor); - if (!active) { - active = true; - runner = Thread(this); - } -} - -void TimerA::stop() -{ - signalStop(); - runner.join(); -} - -void TimerA::signalStop() -{ - Monitor::ScopedLock l(monitor); - if (active) { - active = false; - monitor.notifyAll(); - } -} - -void qpid::broker::intrusive_ptr_add_ref(TimerTaskA* fe) -{ - fe->ref(); -} - -void qpid::broker::intrusive_ptr_release(TimerTaskA* fe) -{ - fe->unref(); - if (fe->refcnt() == 0) delete fe; -} - - |