diff options
Diffstat (limited to 'cppe/src')
-rwxr-xr-x | cppe/src/IceE/Communicator.cpp | 7 | ||||
-rw-r--r-- | cppe/src/IceE/Instance.cpp | 2 | ||||
-rw-r--r-- | cppe/src/IceE/ObjectAdapter.cpp | 144 | ||||
-rw-r--r-- | cppe/src/IceE/ObjectAdapterFactory.cpp | 41 | ||||
-rw-r--r-- | cppe/src/IceE/ObjectAdapterFactory.h | 2 |
5 files changed, 136 insertions, 60 deletions
diff --git a/cppe/src/IceE/Communicator.cpp b/cppe/src/IceE/Communicator.cpp index 8f406a4f733..2bce6e034ff 100755 --- a/cppe/src/IceE/Communicator.cpp +++ b/cppe/src/IceE/Communicator.cpp @@ -60,6 +60,13 @@ Ice::Communicator::waitForShutdown() { _instance->objectAdapterFactory()->waitForShutdown(); } + +bool +Ice::Communicator::isShutdown() const +{ + return _instance->objectAdapterFactory()->isShutdown(); +} + #endif ObjectPrx diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp index 5d7977c5fd0..990c0b341d3 100644 --- a/cppe/src/IceE/Instance.cpp +++ b/cppe/src/IceE/Instance.cpp @@ -685,7 +685,7 @@ IceInternal::Instance::destroy() if(_objectAdapterFactory) { - _objectAdapterFactory->waitForShutdown(); + _objectAdapterFactory->destroy(); } if(_outgoingConnectionFactory) diff --git a/cppe/src/IceE/ObjectAdapter.cpp b/cppe/src/IceE/ObjectAdapter.cpp index e11b3187081..0e579947ca5 100644 --- a/cppe/src/IceE/ObjectAdapter.cpp +++ b/cppe/src/IceE/ObjectAdapter.cpp @@ -224,7 +224,6 @@ Ice::ObjectAdapter::deactivate() wait(); } - #ifdef ICEE_HAS_ROUTER if(_routerInfo) { @@ -284,75 +283,116 @@ Ice::ObjectAdapter::deactivate() void Ice::ObjectAdapter::waitForDeactivate() { + vector<IceInternal::IncomingConnectionFactoryPtr> incomingConnectionFactories; + { - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - // - // First we wait for deactivation of the adapter itself, and for - // the return of all direct method calls using this adapter. - // - while(!_deactivated || _directCount > 0) - { - wait(); - } + if(_destroyed) + { + return; + } - // - // If some other thread is currently deactivating, we wait - // until this thread is finished. - // - while(_waitForDeactivate) - { - wait(); - } - _waitForDeactivate = true; + // + // Wait for deactivation of the adapter itself, and for + // the return of all direct method calls using this adapter. + // + while(!_deactivated || _directCount > 0) + { + wait(); + } + + incomingConnectionFactories = _incomingConnectionFactories; } // // Now we wait until all incoming connection factories are // finished. // - for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), - Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished)); + for_each(incomingConnectionFactories.begin(), incomingConnectionFactories.end(), + Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished)); +} + +bool +Ice::ObjectAdapter::isDeactivated() const +{ + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + + return _deactivated; +} + +void +Ice::ObjectAdapter::destroy() +{ + { + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + + // + // Another thread is in the process of destroying the object + // adapter. Wait for it to finish. + // + while(_destroying) + { + wait(); + } + + // + // Object adapter is already destroyed. + // + if(_destroyed) + { + return; + } + + _destroying = true; + } + + // + // Deactivate and wait for completion. + // + deactivate(); + waitForDeactivate(); // // Now it's also time to clean up our servants and servant // locators. // - if(_instance) // Don't destroy twice. - { - _servantManager->destroy(); - } + _servantManager->destroy(); ObjectAdapterFactoryPtr objectAdapterFactory; { - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - - // - // Signal that waiting is complete. - // - _waitForDeactivate = false; - notifyAll(); - - // - // We're done, now we can throw away all incoming connection - // factories. - // - _incomingConnectionFactories.clear(); - - // - // Remove object references (some of them cyclic). - // - _instance = 0; - _communicator = 0; + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + + // + // Signal that destroy is complete. + // + _destroying = false; + _destroyed = true; + notifyAll(); + + // + // We're done, now we can throw away all incoming connection + // factories. + // + _incomingConnectionFactories.clear(); + + // + // Remove object references (some of them cyclic). + // + _instance = 0; + _communicator = 0; #ifdef ICEE_HAS_ROUTER - _routerInfo = 0; + _routerEndpoints.clear(); + _routerInfo = 0; #endif + _publishedEndpoints.clear(); #ifdef ICEE_HAS_LOCATOR - _locatorInfo = 0; + _locatorInfo = 0; #endif - objectAdapterFactory = _objectAdapterFactory; - _objectAdapterFactory = 0; + + objectAdapterFactory = _objectAdapterFactory; + _objectAdapterFactory = 0; } if(objectAdapterFactory) @@ -604,7 +644,8 @@ Ice::ObjectAdapter::ObjectAdapter(const InstancePtr& instance, const Communicato #endif _directCount(0), _waitForActivate(false), - _waitForDeactivate(false) + _destroying(false), + _destroyed(false) { __setNoDelete(true); try @@ -730,10 +771,10 @@ Ice::ObjectAdapter::~ObjectAdapter() Warning out(_instance->initializationData().logger); out << "object adapter `" << _name << "' has not been deactivated"; } - else if(_instance) + else if(!_destroyed) { Warning out(_instance->initializationData().logger); - out << "object adapter `" << _name << "' deactivation had not been waited for"; + out << "object adapter `" << _name << "' has not been destroyed"; } else { @@ -742,7 +783,6 @@ Ice::ObjectAdapter::~ObjectAdapter() assert(_incomingConnectionFactories.empty()); assert(_directCount == 0); assert(!_waitForActivate); - assert(!_waitForDeactivate); } } diff --git a/cppe/src/IceE/ObjectAdapterFactory.cpp b/cppe/src/IceE/ObjectAdapterFactory.cpp index 6cc8fe9209f..20f12bb0906 100644 --- a/cppe/src/IceE/ObjectAdapterFactory.cpp +++ b/cppe/src/IceE/ObjectAdapterFactory.cpp @@ -85,18 +85,11 @@ IceInternal::ObjectAdapterFactory::waitForShutdown() // // Now we wait for deactivation of each object adapter. // - //for_each(_adapters.begin(), _adapters.end(), - //Ice::secondVoidMemFun<const string, ObjectAdapter>(&ObjectAdapter::waitForDeactivate)); for(map<string, ObjectAdapterPtr>::const_iterator p = _adapters.begin(); p != _adapters.end(); ++p) { p->second->waitForDeactivate(); } - // - // We're done, now we can throw away the object adapters. - // - _adapters.clear(); - { IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); @@ -108,6 +101,40 @@ IceInternal::ObjectAdapterFactory::waitForShutdown() } } +bool +IceInternal::ObjectAdapterFactory::isShutdown() const +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + + return _instance == 0; +} + +void +IceInternal::ObjectAdapterFactory::destroy() +{ + // + // First wait for shutdown to finish. + // + waitForShutdown(); + + map<string, ObjectAdapterPtr> adapters; + + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + + adapters = _adapters; + _adapters.clear(); + } + + // + // Now we destroy each object adapter. + // + for(map<string, ObjectAdapterPtr>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) + { + p->second->destroy(); + } +} + ObjectAdapterPtr IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const string& endpoints #ifdef ICEE_HAS_ROUTER diff --git a/cppe/src/IceE/ObjectAdapterFactory.h b/cppe/src/IceE/ObjectAdapterFactory.h index b1aa509fc16..4fa6999d547 100644 --- a/cppe/src/IceE/ObjectAdapterFactory.h +++ b/cppe/src/IceE/ObjectAdapterFactory.h @@ -31,6 +31,8 @@ public: void shutdown(); void waitForShutdown(); + bool isShutdown() const; + void destroy(); ::Ice::ObjectAdapterPtr createObjectAdapter(const std::string&, const std::string& #ifdef ICEE_HAS_ROUTER |