diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-18 06:36:28 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-18 06:36:28 +0000 |
commit | c4a5072ae4c5f3ec63b0b3213d72fda3d274a67c (patch) | |
tree | 5bf3b5d86e4ed5562bbeb60453a69dfed7ecbcbc /cpp/src/Ice/CommunicatorI.cpp | |
parent | bug fix (diff) | |
download | ice-c4a5072ae4c5f3ec63b0b3213d72fda3d274a67c.tar.bz2 ice-c4a5072ae4c5f3ec63b0b3213d72fda3d274a67c.tar.xz ice-c4a5072ae4c5f3ec63b0b3213d72fda3d274a67c.zip |
thread-safe shutdown
Diffstat (limited to 'cpp/src/Ice/CommunicatorI.cpp')
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 05d1aaecc6f..85db7a08a7a 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -13,7 +13,6 @@ #include <Ice/Instance.h> #include <Ice/ProxyFactory.h> #include <Ice/ThreadPool.h> -#include <Ice/ObjectAdapter.h> #include <Ice/ServantFactoryManager.h> #include <Ice/ObjectAdapterFactory.h> #include <Ice/Logger.h> @@ -28,37 +27,40 @@ void Ice::CommunicatorI::destroy() { JTCSyncT<JTCRecursiveMutex> sync(*this); + shutdown(); - _instance->destroy(); - _instance = 0; + + if (_instance) + { + _instance->destroy(); + _instance = 0; + } + + // + // Don't set _threadPool to null here! See the comments in the + // header file. + // } void Ice::CommunicatorI::shutdown() { - JTCSyncT<JTCRecursiveMutex> sync(*this); - if (!_instance) - { - throw CommunicatorDestroyedException(__FILE__, __LINE__); - } - _instance->objectAdapterFactory()->shutdown(); + // + // No mutex locking here! This operation must be signal-safe. + // + _threadPool->initiateServerShutdown(); } void Ice::CommunicatorI::waitForShutdown() { - ThreadPoolPtr threadPool; - + JTCSyncT<JTCRecursiveMutex> sync(*this); + if (!_instance) { - JTCSyncT<JTCRecursiveMutex> sync(*this); - if (!_instance) - { - throw CommunicatorDestroyedException(__FILE__, __LINE__); - } - threadPool = _instance->threadPool(); + throw CommunicatorDestroyedException(__FILE__, __LINE__); } - threadPool->waitUntilServerFinished(); + _threadPool->waitUntilServerFinished(); } ObjectPrx @@ -103,7 +105,7 @@ Ice::CommunicatorI::createObjectAdapterWithEndpoints(const string& name, const s { throw CommunicatorDestroyedException(__FILE__, __LINE__); } - return _instance->objectAdapterFactory() -> createObjectAdapter(name, endpts); + return _instance->objectAdapterFactory()->createObjectAdapter(name, endpts); } void @@ -161,9 +163,25 @@ Ice::CommunicatorI::getPickler() return _instance->pickler(); } -Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties) : - _instance(new Instance(this, properties)) +Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties) { + __setNoDelete(true); + try + { + _instance = new Instance(this, properties); + } + catch(...) + { + __setNoDelete(false); + throw; + } + __setNoDelete(false); + + // + // Se the comments in the header file for an explanation of why we + // need _threadPool directly in CommunicatorI. + // + _threadPool = _instance->threadPool(); } Ice::CommunicatorI::~CommunicatorI() |