You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2009/01/13 19:52:39 UTC
svn commit: r734213 - in /qpid/trunk/qpid/cpp/src/qpid/broker:
DtxManager.cpp DtxWorkRecord.cpp Timer.cpp Timer.h
Author: astitcher
Date: Tue Jan 13 10:52:19 2009
New Revision: 734213
URL: http://svn.apache.org/viewvc?rev=734213&view=rev
Log:
Start to fix Timer to improve encapsulation and then fix
its inbuilt race conditions (mostly due to the awkward
interface of Timer and TimerTask)
Modified:
qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp?rev=734213&r1=734212&r2=734213&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp Tue Jan 13 10:52:19 2009
@@ -126,7 +126,7 @@
intrusive_ptr<DtxTimeout> timeout = record->getTimeout();
if (timeout.get()) {
if (timeout->timeout == secs) return;//no need to do anything further if timeout hasn't changed
- timeout->cancelled = true;
+ timeout->cancel();
}
timeout = intrusive_ptr<DtxTimeout>(new DtxTimeout(secs, *this, xid));
record->setTimeout(timeout);
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.cpp?rev=734213&r1=734212&r2=734213&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.cpp Tue Jan 13 10:52:19 2009
@@ -34,7 +34,7 @@
DtxWorkRecord::~DtxWorkRecord()
{
if (timeout.get()) {
- timeout->cancelled = true;
+ timeout->cancel();
}
}
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp?rev=734213&r1=734212&r2=734213&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp Tue Jan 13 10:52:19 2009
@@ -38,6 +38,9 @@
void TimerTask::reset() { time = AbsTime(AbsTime::now(), duration); }
+void TimerTask::cancel() { cancelled = true; }
+bool TimerTask::isCancelled() const { return cancelled; }
+
Timer::Timer() : active(false)
{
start();
@@ -56,7 +59,7 @@
monitor.wait();
} else {
intrusive_ptr<TimerTask> t = tasks.top();
- if (t->cancelled) {
+ if (t->isCancelled()) {
tasks.pop();
} else if(t->time < AbsTime::now()) {
tasks.pop();
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h?rev=734213&r1=734212&r2=734213&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h Tue Jan 13 10:52:19 2009
@@ -34,7 +34,11 @@
namespace qpid {
namespace broker {
+class Timer;
+
struct TimerTask : public RefCounted {
+ friend class Timer;
+
const qpid::sys::Duration duration;
qpid::sys::AbsTime time;
volatile bool cancelled;
@@ -43,6 +47,8 @@
TimerTask(qpid::sys::AbsTime time);
virtual ~TimerTask();
void reset();
+ void cancel();
+ bool isCancelled() const;
virtual void fire() = 0;
};