[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "transfer" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Oct 13 14:11:21 CDT 2010


branch "transfer" has been updated
       via  cbd33865aeb400d03cc349ac103b0093c7b72fd2 (commit)
      from  cddcb251e434d36849c2abf162bb78e11b0426d1 (commit)

Summary of changes:
 src/BridgeImpl.cpp |   59 ++++++++++++++++++++++++++++++++++++++++++++-------
 src/BridgeImpl.h   |    4 +++
 2 files changed, 55 insertions(+), 8 deletions(-)


- Log -----------------------------------------------------------------
commit cbd33865aeb400d03cc349ac103b0093c7b72fd2
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Oct 13 16:40:20 2010 -0230

    Added a shutdown background thread to allow the bridge to be shutdown as
    a result of removeSessions without causing deadlocks with the caller.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index 0b381a3..42f76ea 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -498,7 +498,7 @@ void AsteriskSCF::BridgeService::BridgeImpl::removeSessions(const AsteriskSCF::S
     //
     if(mSessions.size() < 2)
     {
-        shutdown(current);
+        spawnShutdown();
     }
 }
 
@@ -711,15 +711,24 @@ size_t AsteriskSCF::BridgeService::BridgeImpl::sessionStopped(const AsteriskSCF:
     lg(Debug) << __FUNCTION__ << ": session terminated from " << session->ice_toString() ;
     session->removeBridge(mSessionListenerPrx);
 
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    std::vector<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
-    if(i != mSessions.end())
+    BridgeSessionPtr b;
+    size_t sizeAfter;
+    {
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        std::vector<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
+        if(i != mSessions.end())
+        {
+            b = *i;
+            mSessions.erase(i);
+        }
+        sizeAfter = mSessions.size();
+    }
+    if(b)
     {
-        (*i)->disconnect();
-        mSessions.erase(i);
+        b->disconnect();
     }
 
-    return mSessions.size();
+    return sizeAfter;
 }
 
 void AsteriskSCF::BridgeService::BridgeImpl::statePreCheck()
@@ -741,4 +750,38 @@ std::vector<AsteriskSCF::BridgeService::BridgeImpl::BridgeSessionPtr> AsteriskSC
     boost::shared_lock<boost::shared_mutex> lock(mLock);
     return mSessions;
 }
-    
+
+namespace
+{
+class ShutdownThread : public IceUtil::Thread
+{
+public:
+    ShutdownThread(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge) : 
+        mBridge(bridge)
+    {
+    }
+
+    void run()
+    {
+        try
+        {
+            mBridge->shutdown();
+        }
+        catch(...)
+        {
+        }
+    }
+private:
+    AsteriskSCF::SessionCommunications::V1::BridgePrx mBridge;
+};
+}
+
+void AsteriskSCF::BridgeService::BridgeImpl::spawnShutdown()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mLock);
+    if(!mShutdownThread)
+    {
+        mShutdownThread = new ShutdownThread(mPrx);
+        mShutdownThread->start();
+    }
+}
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index bc61969..5ddd410 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -82,6 +82,7 @@ namespace BridgeService
                         // There are several valid reasons why this might occur, so we'll ignore it and move on.
                         //
                     }
+                    mConnector = 0;
                 }
             }
 
@@ -150,7 +151,10 @@ namespace BridgeService
         SessionCommunications::V1::SessionListenerPrx mSessionListenerPrx;
         AsteriskSCF::SessionCommunications::V1::BridgePrx mPrx;
 
+        IceUtil::Handle<IceUtil::Thread> mShutdownThread;
+
         void statePreCheck();
+        void spawnShutdown();
     };
 
     typedef IceUtil::Handle<BridgeImpl> BridgeImplPtr;

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list