summaryrefslogtreecommitdiff
path: root/cppe/src/IceE/Instance.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-09-06 07:09:57 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-09-06 07:09:57 +0000
commit21273795cf24d77eecee55995a52ce57719c975d (patch)
tree744ddbaa38338f6ead13361f01af333b8649f6e3 /cppe/src/IceE/Instance.cpp
parentfix. (diff)
downloadice-21273795cf24d77eecee55995a52ce57719c975d.tar.bz2
ice-21273795cf24d77eecee55995a52ce57719c975d.tar.xz
ice-21273795cf24d77eecee55995a52ce57719c975d.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=448
Diffstat (limited to 'cppe/src/IceE/Instance.cpp')
-rw-r--r--cppe/src/IceE/Instance.cpp91
1 files changed, 67 insertions, 24 deletions
diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp
index e9497bff3f7..5009ed783af 100644
--- a/cppe/src/IceE/Instance.cpp
+++ b/cppe/src/IceE/Instance.cpp
@@ -58,6 +58,13 @@ extern bool ICE_API nullHandleAbort;
void IceInternal::incRef(Instance* p) { p->__incRef(); }
void IceInternal::decRef(Instance* p) { p->__decRef(); }
+bool
+IceInternal::Instance::destroyed() const
+{
+ IceUtil::RecMutex::Lock sync(*this);
+ return _state == StateDestroyed;
+}
+
CommunicatorPtr
IceInternal::Instance::communicator() const
{
@@ -67,32 +74,35 @@ IceInternal::Instance::communicator() const
PropertiesPtr
IceInternal::Instance::properties() const
{
+ //
+ // No check for destruction. It must be possible to access the
+ // properties after destruction.
+ //
// No mutex lock, immutable.
+ //
return _properties;
}
LoggerPtr
IceInternal::Instance::logger() const
{
- IceUtil::RecMutex::Lock sync(*this);
-
//
- // Don't throw CommunicatorDestroyedException if destroyed. We
- // need the logger also after destructions.
+ // No check for destruction. It must be possible to access the
+ // logger after destruction.
//
+ IceUtil::RecMutex::Lock sync(*this);
return _logger;
}
void
IceInternal::Instance::logger(const LoggerPtr& logger)
{
+ //
+ // No check for destruction. It must be possible to set the logger
+ // after destruction (needed by logger plugins for example to
+ // unset the logger).
+ //
IceUtil::RecMutex::Lock sync(*this);
-
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
-
_logger = logger;
}
@@ -117,7 +127,7 @@ IceInternal::Instance::routerManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -134,7 +144,7 @@ IceInternal::Instance::locatorManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -149,7 +159,7 @@ IceInternal::Instance::referenceFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -162,7 +172,7 @@ IceInternal::Instance::proxyFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -175,7 +185,7 @@ IceInternal::Instance::outgoingConnectionFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -189,7 +199,7 @@ IceInternal::Instance::objectAdapterFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -210,7 +220,7 @@ IceInternal::Instance::endpointFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -238,7 +248,7 @@ IceInternal::Instance::flushBatchRequests()
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -260,18 +270,32 @@ IceInternal::Instance::flushBatchRequests()
void
IceInternal::Instance::setDefaultContext(const Context& ctx)
{
+ IceUtil::RecMutex::Lock sync(*this);
+
+ if(_state == StateDestroyed)
+ {
+ throw CommunicatorDestroyedException(__FILE__, __LINE__);
+ }
+
_defaultContext = ctx;
}
const Context&
IceInternal::Instance::getDefaultContext() const
{
+ IceUtil::RecMutex::Lock sync(*this);
+
+ if(_state == StateDestroyed)
+ {
+ throw CommunicatorDestroyedException(__FILE__, __LINE__);
+ }
+
return _defaultContext;
}
IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const PropertiesPtr& properties) :
_communicator(communicator.get()),
- _destroyed(false),
+ _state(StateActive),
_properties(properties),
_messageSizeMax(0),
_threadPerConnectionStackSize(0)
@@ -466,7 +490,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
IceInternal::Instance::~Instance()
{
- assert(_destroyed);
+ assert(_state == StateDestroyed);
assert(!_referenceFactory);
assert(!_proxyFactory);
assert(!_outgoingConnectionFactory);
@@ -553,10 +577,29 @@ IceInternal::Instance::finishSetup(int& argc, char* argv[])
#endif
}
-void
+void
IceInternal::Instance::destroy()
{
- assert(!_destroyed);
+ {
+ IceUtil::RecMutex::Lock sync(*this);
+
+ //
+ // If the _state is not StateActive then the instance is
+ // either being destroyed, or has already been destroyed.
+ //
+ if(_state != StateActive)
+ {
+ return;
+ }
+
+ //
+ // We cannot set state to StateDestroyed otherwise instance
+ // methods called during the destroy process (such as
+ // outgoingConnectionFactory() from
+ // ObjectAdapterI::deactivate() will cause an exception.
+ //
+ _state = StateDestroyInProgress;
+ }
#ifndef ICEE_PURE_CLIENT
if(_objectAdapterFactory)
@@ -626,6 +669,6 @@ IceInternal::Instance::destroy()
_endpointFactory = 0;
}
- _destroyed = true;
- }
+ _state = StateDestroyed;
+ }
}