diff options
author | Gordon Sim <gsim@apache.org> | 2007-12-12 10:50:58 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2007-12-12 10:50:58 +0000 |
commit | 45cbaf3bf00000c16163468d77d1363171c69a66 (patch) | |
tree | 39b6a8fb33022c0fa2cdf68dc5e2e921bf14d9c5 /cpp | |
parent | c248015f441908139529ce40fee8d43ad3db6dba (diff) | |
download | qpid-python-45cbaf3bf00000c16163468d77d1363171c69a66.tar.gz |
Fixed deadlock on connection close
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@603551 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.cpp | 16 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.h | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index ea467429a1..dd986deec4 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -32,7 +32,7 @@ using namespace qpid::framing; using namespace qpid::sys; ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) - : connector(c), isClosed(false) + : connector(c), isClosed(false), isClosing(false) { handler.in = boost::bind(&ConnectionImpl::incoming, this, _1); handler.out = boost::bind(&Connector::send, connector, _1); @@ -86,11 +86,21 @@ void ConnectionImpl::open(const std::string& host, int port, handler.waitForOpen(); } -void ConnectionImpl::close() +bool ConnectionImpl::setClosing() { Mutex::ScopedLock l(lock); - if (!isClosed) + if (isClosing || isClosed) { + return false; + } + isClosing = true; + return true; +} + +void ConnectionImpl::close() +{ + if (setClosing()) { handler.close(); + } } void ConnectionImpl::idleIn() diff --git a/cpp/src/qpid/client/ConnectionImpl.h b/cpp/src/qpid/client/ConnectionImpl.h index 6cc20a15f6..1fe8ac4653 100644 --- a/cpp/src/qpid/client/ConnectionImpl.h +++ b/cpp/src/qpid/client/ConnectionImpl.h @@ -49,12 +49,14 @@ class ConnectionImpl : public framing::FrameHandler, framing::ProtocolVersion version; sys::Mutex lock; bool isClosed; + bool isClosing; void incoming(framing::AMQFrame& frame); void closed(uint16_t, const std::string&); void idleOut(); void idleIn(); void shutdown(); + bool setClosing(); template <class F> void forChannels(F functor); |