[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Apr 4 14:35:57 CDT 2012


branch "retry_deux" has been updated
       via  80c87649ef2d9c30d53765f5131e14cd2642c8ae (commit)
      from  81ad1b1dbdd5c64ca3588fa3b54c98ca66505767 (commit)

Summary of changes:
 src/InbandTelephonyEvents.cpp      |   28 ++++++++--------------------
 src/MediaOperationFactoryImpl.h    |   18 +++---------------
 src/TranslatorOperationFactory.cpp |   19 ++++++++-----------
 3 files changed, 19 insertions(+), 46 deletions(-)


- Log -----------------------------------------------------------------
commit 80c87649ef2d9c30d53765f5131e14cd2642c8ae
Author: David M. Lee <dlee at digium.com>
Date:   Wed Apr 4 13:52:26 2012 -0500

    Replace ValueOperationContextCookie with ContextResultData

diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index 8f1b754..1ddf177 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -362,24 +362,12 @@ MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
             const StreamSinkPrx& sink,
             const Ice::Current&)
 {
-    // The factory itself doesn't need a lock, so we'll lock the cookie instead to reduce needless
-    // contention.
-    const CreateMediaOperationCookieWithLockPtr cookie(new CreateMediaOperationCookieWithLock);
-    // lock this cookie so that no one will get our results prematurely
-    boost::lock_guard<boost::mutex> lock(cookie->getMutex());
-    OperationContextCookiePtr existingCookie;
-    mOperationContextCache->addOperationContext(operationContext, cookie, existingCookie);
-
-    if (existingCookie)
+    std::pair<bool, CreateMediaOperationCookiePtr> cacheHit =
+        getContextSync<CreateMediaOperationCookiePtr>(mOperationContextCache, operationContext);
+
+    if (cacheHit.first)
     {
-        // retry detected!
-        CreateMediaOperationCookieWithLockPtr c =
-            boost::dynamic_pointer_cast<CreateMediaOperationCookieWithLock>(existingCookie);
-        assert(c);
-        // Even though we're holding a lock on cookie, it's never left this function; no one can be waiting on it.
-        // There's no danger of deadlocking while waiting on the lock for existingCookie.
-        boost::lock_guard<boost::mutex> lockExistingCookie(c->getMutex());
-        return c->get();
+        return cacheHit.second->getResult();
     }
 
     try
@@ -404,17 +392,17 @@ MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
             throw UnsupportedMediaFormatException();
         }
 
-        cookie->set(proxy);
+        cacheHit.second->setResult(proxy);
         return proxy;
     }
     catch (const std::exception& e)
     {
-        cookie->setException(e);
+        cacheHit.second->setException(e);
         throw;
     }
     catch (...)
     {
-        cookie->setException();
+        cacheHit.second->setException();
         throw;
     }
 }
diff --git a/src/MediaOperationFactoryImpl.h b/src/MediaOperationFactoryImpl.h
index b7db27a..a39f709 100644
--- a/src/MediaOperationFactoryImpl.h
+++ b/src/MediaOperationFactoryImpl.h
@@ -1,7 +1,7 @@
 /*
  * Asterisk SCF -- An open-source communications framework.
  *
- * Copyright (C) 2011, Digium, Inc.
+ * Copyright (C) 2011-2012, Digium, Inc.
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk SCF project. Please do not directly contact
@@ -22,6 +22,7 @@
 #include <AsteriskSCF/Logger.h>
 #include <AsteriskSCF/Media/MediaOperationIf.h>
 #include <AsteriskSCF/Operations/OperationContextCache.h>
+#include <AsteriskSCF/Operations/OperationMonitor.h>
 
 #include "MediaOperationReplicationContext.h"
 
@@ -73,21 +74,8 @@ protected:
 
 typedef IceUtil::Handle<MediaOperationFactoryImpl> MediaOperationFactoryImplPtr;
 
-// Implementations typically need this as the cookie for the createMediaOperation
-typedef Operations::ValueOperationContextCookie<AsteriskSCF::Media::V1::MediaOperationPrx> CreateMediaOperationCookie;
+typedef Operations::ContextResultData<AsteriskSCF::Media::V1::MediaOperationPrx> CreateMediaOperationCookie;
 typedef boost::shared_ptr<CreateMediaOperationCookie> CreateMediaOperationCookiePtr;
 
-/**
- * CreateMediaOperationCookie with a mutex.
- */
-class CreateMediaOperationCookieWithLock : public CreateMediaOperationCookie {
-public:
-    boost::mutex &getMutex() { return mMutex; }
-private:
-    boost::mutex mMutex;
-};
-
-typedef boost::shared_ptr<CreateMediaOperationCookieWithLock> CreateMediaOperationCookieWithLockPtr;
-
 } //end namespace MediaOperationsCore
 } //end namespace AsteriskSCF
diff --git a/src/TranslatorOperationFactory.cpp b/src/TranslatorOperationFactory.cpp
index 8c0100e..a9c0405 100644
--- a/src/TranslatorOperationFactory.cpp
+++ b/src/TranslatorOperationFactory.cpp
@@ -1,7 +1,7 @@
 /*
  * Asterisk SCF -- An open-source communications framework.
  *
- * Copyright (C) 2011, Digium, Inc.
+ * Copyright (C) 2011-2012, Digium, Inc.
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk SCF project. Please do not directly contact
@@ -50,15 +50,12 @@ MediaOperationPrx TranslatorOperationFactory::createMediaOperation(
         const StreamSinkPrx& sink,
         const Ice::Current&)
 {
-    boost::shared_lock<boost::shared_mutex> lock(mMutex);
-    const CreateMediaOperationCookiePtr cookie(new CreateMediaOperationCookie);
-    OperationContextCookiePtr existingCookie;
-    mOperationContextCache->addOperationContext(operationContext, cookie, existingCookie);
+    std::pair<bool, CreateMediaOperationCookiePtr> cacheHit =
+        getContextSync<CreateMediaOperationCookiePtr>(mOperationContextCache, operationContext);
 
-    if (existingCookie)
+    if (cacheHit.first)
     {
-        CreateMediaOperationCookiePtr c = boost::dynamic_pointer_cast<CreateMediaOperationCookie>(existingCookie);
-        return c->get();
+        return cacheHit.second->getResult();
     }
 
     try
@@ -111,17 +108,17 @@ MediaOperationPrx TranslatorOperationFactory::createMediaOperation(
             *supportedOutput,
             *supportedInput,
             IceUtil::generateUUID());
-        cookie->set(r);
+        cacheHit.second->setResult(r);
         return r;
     }
     catch (const std::exception& e)
     {
-        cookie->setException(e);
+        cacheHit.second->setException(e);
         throw;
     }
     catch (...)
     {
-        cookie->setException();
+        cacheHit.second->setException();
         throw;
     }
 }

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


-- 
asterisk-scf/integration/media_operations_core.git



More information about the asterisk-scf-commits mailing list