summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2009-05-07 15:25:30 -0230
committerDwayne Boone <dwayne@zeroc.com>2009-05-07 15:25:30 -0230
commit370dc0863d9d68cec1eee465c16248b845ebb45c (patch)
tree61b45a55b73c6b4b7392d0f2bf82c53db1ce7690 /cpp
parentAdd -rdynamic linker flag (diff)
downloadice-370dc0863d9d68cec1eee465c16248b845ebb45c.tar.bz2
ice-370dc0863d9d68cec1eee465c16248b845ebb45c.tar.xz
ice-370dc0863d9d68cec1eee465c16248b845ebb45c.zip
Bug 3966 - deadlock in LocatorInfo
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Ice/LocatorInfo.cpp48
-rw-r--r--cpp/src/Ice/LocatorInfo.h3
2 files changed, 38 insertions, 13 deletions
diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp
index 4271e3ceaab..4cd06442f3b 100644
--- a/cpp/src/Ice/LocatorInfo.cpp
+++ b/cpp/src/Ice/LocatorInfo.cpp
@@ -514,7 +514,8 @@ IceInternal::LocatorInfo::Request::exception(const Ice::Exception& ex)
IceInternal::LocatorInfo::LocatorInfo(const LocatorPrx& locator, const LocatorTablePtr& table, bool background) :
_locator(locator),
_table(table),
- _background(background)
+ _background(background),
+ _waitForRegistry(false)
{
assert(_locator);
assert(_table);
@@ -523,7 +524,7 @@ IceInternal::LocatorInfo::LocatorInfo(const LocatorPrx& locator, const LocatorTa
void
IceInternal::LocatorInfo::destroy()
{
- IceUtil::Mutex::Lock sync(*this);
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
_locatorRegistry = 0;
_table->clear();
@@ -559,19 +560,42 @@ IceInternal::LocatorInfo::getLocator() const
LocatorRegistryPrx
IceInternal::LocatorInfo::getLocatorRegistry()
{
- IceUtil::Mutex::Lock sync(*this);
+ LocatorPrx locator;
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
+
+ while(_waitForRegistry)
+ {
+ wait();
+ }
+
+ if(_locatorRegistry)
+ {
+ return _locatorRegistry;
+ }
+
+ _waitForRegistry = true;
+ locator = _locator;
+ }
+
+ //
+ // Do not make locator calls from within sync.
+ //
+ LocatorRegistryPrx locatorRegistry = locator->getRegistry();
- if(!_locatorRegistry) // Lazy initialization.
{
- _locatorRegistry = _locator->getRegistry();
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
//
// The locator registry can't be located.
//
- _locatorRegistry = LocatorRegistryPrx::uncheckedCast(_locatorRegistry->ice_locator(0));
- }
+ _locatorRegistry = LocatorRegistryPrx::uncheckedCast(locatorRegistry->ice_locator(0));
+
+ _waitForRegistry = false;
+ notifyAll();
- return _locatorRegistry;
+ return _locatorRegistry;
+ }
}
vector<EndpointIPtr>
@@ -845,7 +869,7 @@ IceInternal::LocatorInfo::trace(const string& msg, const ReferencePtr& ref, cons
IceInternal::LocatorInfo::RequestPtr
IceInternal::LocatorInfo::getAdapterRequest(const ReferencePtr& ref)
{
- IceUtil::Mutex::Lock sync(*this);
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
@@ -866,7 +890,7 @@ IceInternal::LocatorInfo::getAdapterRequest(const ReferencePtr& ref)
IceInternal::LocatorInfo::RequestPtr
IceInternal::LocatorInfo::getObjectRequest(const ReferencePtr& ref)
{
- IceUtil::Mutex::Lock sync(*this);
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
@@ -912,7 +936,7 @@ IceInternal::LocatorInfo::finishRequest(const ReferencePtr& ref,
_table->removeAdapterEndpoints(ref->getAdapterId());
}
- IceUtil::Mutex::Lock sync(*this);
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
assert(_adapterRequests.find(ref->getAdapterId()) != _adapterRequests.end());
_adapterRequests.erase(ref->getAdapterId());
}
@@ -927,7 +951,7 @@ IceInternal::LocatorInfo::finishRequest(const ReferencePtr& ref,
_table->removeObjectReference(ref->getIdentity());
}
- IceUtil::Mutex::Lock sync(*this);
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
assert(_objectRequests.find(ref->getIdentity()) != _objectRequests.end());
_objectRequests.erase(ref->getIdentity());
}
diff --git a/cpp/src/Ice/LocatorInfo.h b/cpp/src/Ice/LocatorInfo.h
index 2d44d050a4a..cfc8e2c22ba 100644
--- a/cpp/src/Ice/LocatorInfo.h
+++ b/cpp/src/Ice/LocatorInfo.h
@@ -73,7 +73,7 @@ private:
std::map<Ice::Identity, std::pair<IceUtil::Time, ReferencePtr> > _objectMap;
};
-class LocatorInfo : public IceUtil::Shared, public IceUtil::Mutex
+class LocatorInfo : public IceUtil::Shared, public IceUtil::Monitor<IceUtil::Mutex>
{
public:
@@ -175,6 +175,7 @@ private:
Ice::LocatorRegistryPrx _locatorRegistry;
const LocatorTablePtr _table;
const bool _background;
+ bool _waitForRegistry;
std::map<std::string, RequestPtr> _adapterRequests;
std::map<Ice::Identity, RequestPtr> _objectRequests;