[dss-commits] digitalSTROM Server branch, 0.6, updated. 3c149f4b4740dc3370996145e520b7ac2e4b3f68

git version control dss-commits at forum.digitalstrom.org
Fri Nov 13 15:13:53 CET 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".

The branch, 0.6 has been updated
       via  3c149f4b4740dc3370996145e520b7ac2e4b3f68 (commit)
      from  942d832b4a08e6126d95a0eb57a1ca051017f87d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3c149f4b4740dc3370996145e520b7ac2e4b3f68
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Fri Nov 13 14:45:16 2009 +0100

    Fixed a race-condition in DS485Proxy::execute
    
    Fixes #197
    
    FrameBucketBase handled it's registration/de-registration in it's
    constructor/destructor. This was no problem until we've introduced
    a base-class that made FrameBucketBase::addFrame pure virtual.
    
    If a descendant of FrameBucketBase gets destoyed, it will remain
    in the bucket list of the proxy until FrameBucketBases destructor
    got called. During that short period the entry of addFrame in the
    vmt is of that object is null, as the descendant's destructor has
    already been called.
    
    I've taken out the automagic registration and replaced with manual
    registration/de-registration. To ensure that allocated buckets get
    removed from the bucket list I've added a static function that
    can be passed to a boost::shared_ptr.

-----------------------------------------------------------------------

Changes:
diff --git a/core/ds485client.cpp b/core/ds485client.cpp
index 46da99e..13c1064 100644
--- a/core/ds485client.cpp
+++ b/core/ds485client.cpp
@@ -104,7 +104,8 @@ namespace dss {
     DS485Proxy* proxy = dynamic_cast<DS485Proxy*>(&DSS::getInstance()->getDS485Interface());
     assert(proxy != NULL);
 
-    boost::shared_ptr<FrameBucketBase> bucket(new FrameBucketCallback(proxy, _functionID, _source, _callback));
+    boost::shared_ptr<FrameBucketBase> bucket(new FrameBucketCallback(proxy, _functionID, _source, _callback), FrameBucketBase::removeFromProxyAndDelete);
+    bucket->addToProxy();
     m_pImpl->buckets.push_back(bucket);
   } // subscribeTo
 
diff --git a/unix/ds485proxy.cpp b/unix/ds485proxy.cpp
index f009a0f..aaee1d6 100644
--- a/unix/ds485proxy.cpp
+++ b/unix/ds485proxy.cpp
@@ -500,7 +500,8 @@ namespace dss {
 
   boost::shared_ptr<FrameBucketCollector> DS485Proxy::sendFrameAndInstallBucket(DS485CommandFrame& _frame, const int _functionID) {
     int sourceID = _frame.getHeader().isBroadcast() ? -1 :  _frame.getHeader().getDestination();
-    boost::shared_ptr<FrameBucketCollector> result(new FrameBucketCollector(this, _functionID, sourceID));
+    boost::shared_ptr<FrameBucketCollector> result(new FrameBucketCollector(this, _functionID, sourceID), FrameBucketBase::removeFromProxyAndDelete);
+    result->addToProxy();
     sendFrame(_frame);
     return result;
   } // sendFrameAndInstallBucket
@@ -1493,14 +1494,23 @@ namespace dss {
     m_FunctionID(_functionID),
     m_SourceID(_sourceID)
   {
-    Logger::getInstance()->log("Bucket: Registering for fid: " + intToString(_functionID) + " sid: " + intToString(_sourceID));
-    m_pProxy->addFrameBucket(this);
+    assert(m_pProxy != NULL);
   } // ctor
 
-  FrameBucketBase::~FrameBucketBase() {
+  void FrameBucketBase::addToProxy() {
+    Logger::getInstance()->log("Bucket: Registering for fid: " + intToString(m_FunctionID) + " sid: " + intToString(m_SourceID));
+    m_pProxy->addFrameBucket(this);
+  } // addToProxy
+
+  void FrameBucketBase::removeFromProxyAndDelete(FrameBucketBase* _obj) {
+    _obj->removeFromProxy();
+    delete _obj;
+  } // remove_from_proxy_and_delete
+
+  void FrameBucketBase::removeFromProxy() {
     Logger::getInstance()->log("Bucket: Removing for fid: " + intToString(m_FunctionID) + " sid: " + intToString(m_SourceID));
     m_pProxy->removeFrameBucket(this);
-  } // dtor
+  } // removeFromProxy
 
 
   //================================================== FrameBucket
diff --git a/unix/ds485proxy.h b/unix/ds485proxy.h
index 6d15b0d..b7066bd 100644
--- a/unix/ds485proxy.h
+++ b/unix/ds485proxy.h
@@ -84,12 +84,19 @@ namespace dss {
   class FrameBucketBase {
   public:
     FrameBucketBase(DS485Proxy* _proxy, int _functionID, int _sourceID);
-    virtual ~FrameBucketBase();
+    virtual ~FrameBucketBase() {}
 
     int getFunctionID() const { return m_FunctionID; }
     int getSourceID() const { return m_SourceID; }
 
     virtual bool addFrame(boost::shared_ptr<ReceivedFrame> _frame) = 0;
+
+    /** Registers the bucket at m_pProxy */
+    void addToProxy();
+    /** Removes the bucket from m_pProxy */
+    void removeFromProxy();
+    /** Static function to be used from a boost::shared_ptr as a deleter. */
+    static void removeFromProxyAndDelete(FrameBucketBase* _obj);
   private:
     DS485Proxy* m_pProxy;
     int m_FunctionID;


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list