[asterisk-scf-commits] asterisk-scf/release/ice-util-cpp.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Apr 22 12:46:50 CDT 2011
branch "master" has been updated
via e8001bdd50f0847b886fa85544e5be4ce85292c5 (commit)
from ff03bb063c8737d5ed3dbb31372269be9080fb1c (commit)
Summary of changes:
SmartProxy/include/AsteriskSCF/SmartProxy.h | 47 ++++++++++-----------------
1 files changed, 17 insertions(+), 30 deletions(-)
- Log -----------------------------------------------------------------
commit e8001bdd50f0847b886fa85544e5be4ce85292c5
Author: Brent Eagles <beagles at digium.com>
Date: Fri Apr 22 15:15:37 2011 -0230
Merged branch smartproxy-threadsafety-update. Includes changes that:
* Change catch block to catch only those exceptions that should result in
retrying the locate call.
* Modified initialization and the reference operator to be more consistent
if multiple threads invoke the assignment and reference operators concurrently.
diff --git a/SmartProxy/include/AsteriskSCF/SmartProxy.h b/SmartProxy/include/AsteriskSCF/SmartProxy.h
index 27b8961..50463e9 100644
--- a/SmartProxy/include/AsteriskSCF/SmartProxy.h
+++ b/SmartProxy/include/AsteriskSCF/SmartProxy.h
@@ -67,17 +67,18 @@ public:
initialize();
}
- P& operator->()
+ P operator->()
{
// everything this calls is thread safe. no need to lock.
assert(mServiceLocator && mLocatorParams);
- if (!initializeOnce())
+ P t = initialize();
+ if (!t)
{
throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
}
- return mProxy;
+ return t;
}
SmartProxy &operator=(const SmartProxy &rhs)
@@ -105,51 +106,36 @@ public:
return mProxy != 0;
}
- /**
- * Initializes this SmartProxy, but only if it hasn't already been
- * initialized.
- *
- * @return True if initialization successful; false if unsuccessful.
- */
- bool initializeOnce()
- {
- // isInitialized() and initialize() are thread safe. no need to lock
- if (isInitialized())
- {
- return true;
- }
-
- // Try again to initialize.
- initialize();
- return isInitialized();
- }
-
private:
/**
* Initialization. Primarily involves acquring access to specific IceStorm
* topic.
*/
- void initialize()
+ P initialize()
{
// thread safe
IceUtil::Mutex::Lock myLock(mMutex);
-
+ if (mProxy)
+ {
+ return mProxy;
+ }
+
using namespace AsteriskSCF::System::Logging;
if (!mServiceLocator)
{
// uninitialized; probably no logger setup yet, either
std::clog << "Missing ServiceLocator proxy. Cannot initialize.\n";
- return;
+ return 0;
}
-
+
// all paths to set mServiceLocator also set mLogger.
// but just in case things change in the future...
assert(mLogger);
-
+
if (!mLocatorParams)
{
(*mLogger)(Error) << "Cannot find service with null parameters";
- return;
+ return 0;
}
try
@@ -163,17 +149,18 @@ private:
<< ") isn't of expected type";
}
}
- catch (const Ice::Exception &e)
+ catch (const Ice::SyscallException& e)
{
(*mLogger)(Error) << "Exception locating "
<< mLocatorParams->category << ": " << e.what();
- return;
+ return 0;
}
if (mProxy == 0)
{
(*mLogger)(Error) << "Unable to locate " << mLocatorParams->category;
}
+ return mProxy;
}
void copy(const SmartProxy &rhs)
-----------------------------------------------------------------------
--
asterisk-scf/release/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list