[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
Thu Mar 22 10:44:17 CDT 2012
branch "retry_deux" has been updated
via b0bd266487b0f665edcac1cc784b7a09e2654e52 (commit)
from 1d23331df6c10c92fa72e11e911acaa16a626bdd (commit)
Summary of changes:
src/InbandTelephonyEvents.cpp | 14 ++++++++++++--
src/MediaOperationFactoryImpl.h | 12 ++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
- Log -----------------------------------------------------------------
commit b0bd266487b0f665edcac1cc784b7a09e2654e52
Author: David M. Lee <dlee at digium.com>
Date: Thu Mar 22 10:43:11 2012 -0500
Thread safety for createMediaOperation
diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index 5b5524a..bf4174b 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -362,13 +362,23 @@ MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
const StreamSinkPrx& sink,
const Ice::Current&)
{
- const CreateMediaOperationCookiePtr cookie(new CreateMediaOperationCookie);
+ // 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)
{
- CreateMediaOperationCookiePtr c = boost::dynamic_pointer_cast<CreateMediaOperationCookie>(existingCookie);
+ // 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();
}
diff --git a/src/MediaOperationFactoryImpl.h b/src/MediaOperationFactoryImpl.h
index 61715bd..b7db27a 100644
--- a/src/MediaOperationFactoryImpl.h
+++ b/src/MediaOperationFactoryImpl.h
@@ -77,5 +77,17 @@ typedef IceUtil::Handle<MediaOperationFactoryImpl> MediaOperationFactoryImplPtr;
typedef Operations::ValueOperationContextCookie<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
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_operations_core.git
More information about the asterisk-scf-commits
mailing list