simplify InternalChannelImpl::destroy()

Collapse channel destroy(bool) and destroyChannel() into destroy()
This commit is contained in:
Michael Davidsaver
2018-04-04 18:48:48 -07:00
parent e97354db61
commit 128d4b67f9
2 changed files with 34 additions and 62 deletions

View File

@@ -3305,7 +3305,40 @@ private:
virtual void destroy() OVERRIDE FINAL
{
destroy(false);
{
Lock guard(m_channelMutex);
if (m_connectionState == DESTROYED)
return;
REFTRACE_DECREMENT(num_active);
m_getfield.reset();
// stop searching...
shared_pointer thisChannelPointer = internal_from_this();
m_context->getChannelSearchManager()->unregisterSearchInstance(thisChannelPointer);
disconnectPendingIO(true);
if (m_connectionState == CONNECTED)
{
disconnect(false, true);
}
else if (m_transport)
{
// unresponsive state, do not forget to release transport
m_transport->release(getID());
m_transport.reset();
}
setConnectionState(DESTROYED);
// unregister
m_context->unregisterChannel(thisChannelPointer);
}
// should be called without any lock hold
reportChannelStateChange();
}
virtual string getRequesterName() OVERRIDE FINAL
@@ -3482,66 +3515,6 @@ public:
reportChannelStateChange();
}
/**
* @param force force destruction regardless of reference count (not used now)
*/
void destroy(bool force) {
{
Lock guard(m_channelMutex);
if (m_connectionState == DESTROYED)
return;
//throw std::runtime_error("Channel already destroyed.");
}
REFTRACE_DECREMENT(num_active);
destroyChannel(force);
}
/**
* Actual destroy method, to be called <code>CAJContext</code>.
* @param force force destruction regardless of reference count
* @throws PVAException
* @throws std::runtime_error
* @throws IOException
*/
void destroyChannel(bool /*force*/) OVERRIDE FINAL {
{
Lock guard(m_channelMutex);
if (m_connectionState == DESTROYED)
throw std::runtime_error("Channel already destroyed.");
m_getfield.reset();
// stop searching...
shared_pointer thisChannelPointer = internal_from_this();
m_context->getChannelSearchManager()->unregisterSearchInstance(thisChannelPointer);
disconnectPendingIO(true);
if (m_connectionState == CONNECTED)
{
disconnect(false, true);
}
else if (m_transport)
{
// unresponsive state, do not forget to release transport
m_transport->release(getID());
m_transport.reset();
}
setConnectionState(DESTROYED);
// unregister
m_context->unregisterChannel(thisChannelPointer);
}
// should be called without any lock hold
reportChannelStateChange();
}
/**
* Disconnected notification.
* @param initiateSearch flag to indicate if searching (connect) procedure should be initiated