qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r601803 - in /incubator/qpid/trunk/qpid/cpp/src: qpid/broker/DtxManager.cpp qpid/broker/DtxTimeout.h qpid/broker/DtxWorkRecord.h qpid/broker/Timer.cpp qpid/broker/Timer.h qpid/management/ManagementAgent.cpp tests/TimerTest.cpp
Date Thu, 06 Dec 2007 18:22:21 GMT
Author: aconway
Date: Thu Dec  6 10:22:17 2007
New Revision: 601803

URL: http://svn.apache.org/viewvc?rev=601803&view=rev
Log:

Removed redundant TimerA, use intrusive_ptr for Timer.

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxTimeout.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/TimerTest.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxManager.cpp Thu Dec  6 10:22:17 2007
@@ -119,12 +119,12 @@
 void DtxManager::setTimeout(const std::string& xid, uint32_t secs)
 {
     DtxWorkRecord* record = getWork(xid);
-    DtxTimeout::shared_ptr timeout = record->getTimeout();
+    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 = DtxTimeout::shared_ptr(new DtxTimeout(secs, *this, xid));
+    timeout = intrusive_ptr<DtxTimeout>(new DtxTimeout(secs, *this, xid));
     record->setTimeout(timeout);
     timer.add(boost::static_pointer_cast<TimerTask>(timeout));
     
@@ -132,7 +132,7 @@
 
 uint32_t DtxManager::getTimeout(const std::string& xid)
 {
-    DtxTimeout::shared_ptr timeout = getWork(xid)->getTimeout();
+    intrusive_ptr<DtxTimeout> timeout = getWork(xid)->getTimeout();
     return !timeout ? 0 : timeout->timeout;
 }
 
@@ -145,7 +145,7 @@
     } else {
         get_pointer(i)->timedout();
         //TODO: do we want to have a timed task to cleanup, or can we rely on an explicit
completion?
-        //timer.add(TimerTask::shared_ptr(new DtxCleanup(60*30/*30 mins*/, *this, xid)));
+        //timer.add(intrusive_ptr<TimerTask>(new DtxCleanup(60*30/*30 mins*/, *this,
xid)));
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxTimeout.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxTimeout.h?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxTimeout.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxTimeout.h Thu Dec  6 10:22:17 2007
@@ -33,7 +33,6 @@
 
 struct DtxTimeout : public TimerTask
 {
-    typedef boost::shared_ptr<DtxTimeout> shared_ptr;
     const uint32_t timeout;
     DtxManager& mgr;
     const std::string xid;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.h?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxWorkRecord.h Thu Dec  6 10:22:17 2007
@@ -48,7 +48,7 @@
     bool rolledback;
     bool prepared;
     bool expired;
-    DtxTimeout::shared_ptr timeout;
+    intrusive_ptr<DtxTimeout> timeout;
     Work work;
     std::auto_ptr<TPCTransactionContext> txn;
     qpid::sys::Mutex lock;
@@ -65,8 +65,8 @@
     void add(DtxBuffer::shared_ptr ops);
     void recover(std::auto_ptr<TPCTransactionContext> txn, DtxBuffer::shared_ptr ops);
     void timedout();
-    void setTimeout(DtxTimeout::shared_ptr t) { timeout = t; }
-    DtxTimeout::shared_ptr getTimeout() { return timeout; }
+    void setTimeout(intrusive_ptr<DtxTimeout> t) { timeout = t; }
+    intrusive_ptr<DtxTimeout> getTimeout() { return timeout; }
 };
 
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.cpp Thu Dec  6 10:22:17 2007
@@ -27,9 +27,14 @@
 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 @@
         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::add(TimerTask::shared_ptr task)
+void Timer::add(intrusive_ptr<TimerTask> task)
 {
     Monitor::ScopedLock l(monitor);
     tasks.push(task);
@@ -93,92 +98,9 @@
     }
 }
 
-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;
-}
-
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Timer.h Thu Dec  6 10:22:17 2007
@@ -21,22 +21,19 @@
 #ifndef _Timer_
 #define _Timer_
 
-#include <memory>
-#include <queue>
-#include <boost/shared_ptr.hpp>
-#include <boost/intrusive_ptr.hpp>
 #include "qpid/sys/Monitor.h"
 #include "qpid/sys/Thread.h"
 #include "qpid/sys/Runnable.h"
+#include "qpid/RefCounted.h"
+
+#include <memory>
+#include <queue>
 
 namespace qpid {
 namespace broker {
 
-struct TimerTask
-{
+struct TimerTask : public RefCounted {
     const qpid::sys::Duration duration;
-    typedef boost::shared_ptr<TimerTask> shared_ptr;
-
     qpid::sys::AbsTime time;
     volatile bool cancelled;
 
@@ -47,79 +44,35 @@
     virtual void fire() = 0;
 };
 
-struct TimerTaskA : public TimerTask
-{
-    typedef boost::intrusive_ptr<TimerTaskA> intrusive_ptr;
-
-    TimerTaskA(qpid::sys::Duration timeout);
-    TimerTaskA(qpid::sys::AbsTime time);
-    virtual ~TimerTaskA();
-    
-    size_t          ref_cnt;
-    inline size_t refcnt(void) { return ref_cnt;}
-    inline void ref(void) { ref_cnt++; }
-    inline void unref(void) { ref_cnt--; }
+struct Later {
+    bool operator()(const intrusive_ptr<TimerTask>& a,
+                    const intrusive_ptr<TimerTask>& b) const;
 };
 
-struct Later
-{
-    bool operator()(const TimerTask::shared_ptr& a, const TimerTask::shared_ptr&
b) const;
-};
-
-struct LaterA
-{
-     bool operator()(const TimerTaskA::intrusive_ptr& a, const TimerTaskA::intrusive_ptr&
b) const;
-};
-
-
-class Timer : private qpid::sys::Runnable
-{
-protected:
+class Timer : private qpid::sys::Runnable {
+  protected:
     qpid::sys::Monitor monitor;            
-    std::priority_queue<TimerTask::shared_ptr, std::vector<TimerTask::shared_ptr>,
Later> tasks;
+    std::priority_queue<intrusive_ptr<TimerTask>,
+                        std::vector<intrusive_ptr<TimerTask> >,
+                        Later> tasks;
     qpid::sys::Thread runner;
     bool active;
 
     virtual void run();
     void signalStop();
 
-public:
+  public:
     Timer();
     virtual ~Timer();
 
-    void add(TimerTask::shared_ptr task);
+    void add(intrusive_ptr<TimerTask> task);
     void start();
     void stop();
 
 };
 
-class TimerA : private qpid::sys::Runnable
-{
-protected:
-    qpid::sys::Monitor monitor;            
-    std::priority_queue<TimerTaskA::intrusive_ptr&, std::vector<TimerTaskA::intrusive_ptr>,
-             LaterA> itasks;
-    qpid::sys::Thread runner;
-    bool active;
-    
-    virtual void run();
-    void signalStop();
-
-public:
-    TimerA();
-    virtual ~TimerA();
-
-    void add(TimerTaskA::intrusive_ptr& task);
-    void start();
-    void stop();
-};
-
-void intrusive_ptr_add_ref(TimerTaskA* r);
-void intrusive_ptr_release(TimerTaskA* r);
-
 
-}
-}
+}}
 
 
 #endif

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp Thu Dec  6 10:22:17
2007
@@ -36,7 +36,7 @@
 
 ManagementAgent::ManagementAgent (uint16_t _interval) : interval (_interval)
 {
-    timer.add (TimerTask::shared_ptr (new Periodic(*this, interval)));
+    timer.add (intrusive_ptr<TimerTask> (new Periodic(*this, interval)));
     nextObjectId = uint64_t (qpid::sys::Duration (qpid::sys::now ()));
 }
 
@@ -68,7 +68,7 @@
 
 void ManagementAgent::Periodic::fire ()
 {
-    agent.timer.add (TimerTask::shared_ptr (new Periodic (agent, agent.interval)));
+    agent.timer.add (intrusive_ptr<TimerTask> (new Periodic (agent, agent.interval)));
     agent.PeriodicProcessing ();
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/TimerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/TimerTest.cpp?rev=601803&r1=601802&r2=601803&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/TimerTest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/TimerTest.cpp Thu Dec  6 10:22:17 2007
@@ -30,6 +30,7 @@
 
 using namespace qpid::broker;
 using namespace qpid::sys;
+using qpid::intrusive_ptr;
 using boost::dynamic_pointer_cast;
 
 class TimerTest : public CppUnit::TestCase  
@@ -104,10 +105,10 @@
     {
         Counter counter;
         Timer timer;
-        TestTask::shared_ptr task1(new TestTask(Duration(3 * TIME_SEC), counter));
-        TestTask::shared_ptr task2(new TestTask(Duration(1 * TIME_SEC), counter));
-        TestTask::shared_ptr task3(new TestTask(Duration(4 * TIME_SEC), counter));
-        TestTask::shared_ptr task4(new TestTask(Duration(2 * TIME_SEC), counter));
+        intrusive_ptr<TestTask> task1(new TestTask(Duration(3 * TIME_SEC), counter));
+        intrusive_ptr<TestTask> task2(new TestTask(Duration(1 * TIME_SEC), counter));
+        intrusive_ptr<TestTask> task3(new TestTask(Duration(4 * TIME_SEC), counter));
+        intrusive_ptr<TestTask> task4(new TestTask(Duration(2 * TIME_SEC), counter));
         
         timer.add(task1);
         timer.add(task2);



Mime
View raw message