[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "async-bridging" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Apr 8 08:38:49 CDT 2011
branch "async-bridging" has been updated
via 89acedd55e118224f161bb5068d327920755a1e5 (commit)
from 3151febe0ba22f274aabc26b04c498c2a9710019 (commit)
Summary of changes:
src/BridgeImpl.cpp | 7 +++++-
src/BridgeManagerImpl.cpp | 39 ++++++++-----------------------------
src/MediaSplicer.cpp | 46 +++++++++++++-------------------------------
3 files changed, 29 insertions(+), 63 deletions(-)
- Log -----------------------------------------------------------------
commit 89acedd55e118224f161bb5068d327920755a1e5
Author: Brent Eagles <beagles at digium.com>
Date: Fri Apr 8 10:00:43 2011 -0230
Responding to review feedback. Removing some handle usage errors,
dead code, adding some comments and making some code more readable.
diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index d501816..f4a8adc 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -870,7 +870,12 @@ void BridgeImpl::updateState(const BridgeStateItemPtr& state)
{
mLogger(Debug) << FUNLOG;
boost::unique_lock<boost::shared_mutex> lock(mLock);
- *mState.get() = *state.get();
+ //
+ // We perform a deep copy because there are no guarantees about the thread safety of the memory
+ // pointed to be "state" over time. We could "say" that the call acquires ownership, but its
+ // safer to take the added cost of the copy.
+ //
+ *mState = *state;
}
void BridgeImpl::addListener(const BridgeListenerStateItemPtr& update)
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index a051bdc..4ce7a1b 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -110,32 +110,6 @@ private:
typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
-//
-// Functor used with for_each on shutdown.
-//
-class BridgeMgrShutdownImpl :
- public unary_function<BridgeManagerImpl::BridgeInfo, void>
-{
-public:
- //
- // We copy current so we can apply the call context to all of the shutdown calls
- // on the bridge servants.
- //
- BridgeMgrShutdownImpl(const Ice::Current& c) :
- mCurrent(c)
- {
- }
-
- void operator()(const BridgeManagerImpl::BridgeInfo& b)
- {
- b.servant->shutdownImpl(mCurrent);
- }
-
-private:
- const Ice::Current mCurrent;
-};
-
-
BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name, const ReplicatorSmartPrx& replicator,
const Logger& logger) :
mName(name),
@@ -345,9 +319,9 @@ void BridgeManagerImpl::shutdown(const Ice::Current& current)
mLogger(Info) << current.adapter->getCommunicator()->identityToString(current.id) << ": shutting down." ;
mState->runningState = AsteriskSCF::Bridge::V1::ShuttingDown;
reap();
- if (mBridges.size() > 0)
+ for (vector<BridgeInfo>::iterator i = mBridges.begin(); i != mBridges.end(); ++i)
{
- for_each(mBridges.begin(), mBridges.end(), BridgeMgrShutdownImpl(current));
+ i->servant->shutdownImpl(current);
}
if (mListeners && !mListeners->isSuspended())
@@ -370,7 +344,7 @@ BridgeManagerStateItemPtr BridgeManagerImpl::getState()
//
// Copy it instead of passing a reference for thread safety.
//
- BridgeManagerStateItemPtr result(new BridgeManagerStateItem(*(mState.get())));
+ BridgeManagerStateItemPtr result(new BridgeManagerStateItem(*mState));
result->listeners = mListeners->getListeners();
return result;
}
@@ -379,7 +353,12 @@ void BridgeManagerImpl::updateState(const BridgeManagerStateItemPtr& state)
{
mLogger(Debug) << FUNLOG;
boost::unique_lock<boost::shared_mutex> lock(mLock);
- *mState.get() = *state.get();
+ //
+ // We perform a deep copy because there are no guarantees about the thread safety of the memory
+ // pointed to be "state" over time. We could "say" that the call acquires ownership, but its
+ // safer to take the added cost of the copy.
+ //
+ *mState = *state;
}
vector<BridgeServantPtr> BridgeManagerImpl::getBridges()
diff --git a/src/MediaSplicer.cpp b/src/MediaSplicer.cpp
index 132c542..163481d 100644
--- a/src/MediaSplicer.cpp
+++ b/src/MediaSplicer.cpp
@@ -472,8 +472,7 @@ public:
if (!i->connector->isConnected())
{
mLogger(Debug) << FUNLOG << ": reaping a connector";
- MediaSessions::iterator t = i;
- i = mSessions.erase(t);
+ i = mSessions.erase(i);
continue;
}
++i;
@@ -541,19 +540,19 @@ public:
}
vector<OutgoingPairing> result;
- for (StreamSinkSeq::const_iterator i = sinks.begin(); i != sinks.end(); ++i)
+ for (StreamSinkSeq::const_iterator sink = sinks.begin(); sink != sinks.end(); ++sink)
{
bool connected = false;
- for (vector<StreamSourceSeq>::iterator j = allSources.begin(); j != allSources.end() && !connected; ++j)
+ for (vector<StreamSourceSeq>::iterator sources = allSources.begin(); sources != allSources.end() && !connected;
+ ++sources)
{
- for (StreamSourceSeq::iterator k = j->begin(); k != j->end(); ++k)
+ for (StreamSourceSeq::iterator source = sources->begin(); source != sources->end(); ++source)
{
- if (canAdapt(*i, *k))
+ if (canAdapt(*sink, *source))
{
- result.push_back(OutgoingPairing(*i, *k));
+ result.push_back(OutgoingPairing(*sink, *source));
+ sources->erase(source);
connected = true;
- StreamSourceSeq::iterator t = k;
- j->erase(t);
break;
}
}
@@ -582,18 +581,17 @@ public:
}
vector<IncomingPairing> result;
- for (StreamSourceSeq::const_iterator i = sources.begin(); i != sources.end(); ++i)
+ for (StreamSourceSeq::const_iterator source = sources.begin(); source != sources.end(); ++source)
{
bool connected = false;
- for (vector<StreamSinkSeq>::iterator j = allSinks.begin(); j != allSinks.end() && !connected; ++j)
+ for (vector<StreamSinkSeq>::iterator sinks = allSinks.begin(); sinks != allSinks.end() && !connected; ++sinks)
{
- for (StreamSinkSeq::iterator k = j->begin(); k != j->end(); ++k)
+ for (StreamSinkSeq::iterator sink = sinks->begin(); sink != sinks->end(); ++sink)
{
- if (canAdapt(*i, *k))
+ if (canAdapt(*source, *sink))
{
- result.push_back(IncomingPairing(*i, *k));
- StreamSinkSeq::iterator t = k;
- j->erase(t);
+ result.push_back(IncomingPairing(*source, *sink));
+ sink = sinks->erase(sink);
connected = true;
break;
}
@@ -630,22 +628,6 @@ private:
}
};
- class FindImpl : public unary_function<MediaSessionStruct, bool>
- {
- public:
- FindImpl(const SessionPrx& prx) :
- mPrx(prx)
- {
- }
-
- bool operator()(const MediaSessionStruct& b)
- {
- return b.mediaSession == mPrx;
- }
- private:
- SessionPrx mPrx;
- };
-
typedef vector<MediaSessionStruct> MediaSessions;
MediaSessions mSessions;
-----------------------------------------------------------------------
--
asterisk-scf/integration/bridging.git
More information about the asterisk-scf-commits
mailing list