diff options
author | Andrew Stitcher <astitcher@apache.org> | 2009-09-18 19:55:47 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2009-09-18 19:55:47 +0000 |
commit | 7190e1994763e42d208b5e3f17edd53a0d48546a (patch) | |
tree | e440b2420408bbb7970b385de96337e83cd6f082 /cpp/src | |
parent | 1c216e7c77db74b1aa5e197e5d6b4d6f1d8c4f0e (diff) | |
download | qpid-python-7190e1994763e42d208b5e3f17edd53a0d48546a.tar.gz |
Rearrange readCredit logic for correctness
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@816763 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/sys/AsynchIOHandler.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/cpp/src/qpid/sys/AsynchIOHandler.cpp b/cpp/src/qpid/sys/AsynchIOHandler.cpp index 8094abd43d..46d8f3b4f1 100644 --- a/cpp/src/qpid/sys/AsynchIOHandler.cpp +++ b/cpp/src/qpid/sys/AsynchIOHandler.cpp @@ -107,6 +107,23 @@ bool AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) { if (readError) { return false; } + + bool ret = true; + + // Check here for read credit + if (readCredit.get() != InfiniteCredit) { + // TODO In theory should be able to use an atomic operation before taking the lock + // but in practice there seems to be an unexplained race in that case + ScopedLock<Mutex> l(creditLock); + if (--readCredit == 0) { + assert(readCredit.get() >= 0); + if (readCredit.get() == 0) { + aio->stopReading(); + ret = false; + } + } + } + size_t decoded = 0; if (codec) { // Already initiated try { @@ -149,20 +166,7 @@ bool AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) { // Give whole buffer back to aio subsystem aio->queueReadBuffer(buff); } - // Check here for read credit - if (readCredit.get() != InfiniteCredit) { - // TODO In theory should be able to use an atomic operation before taking the lock - // but in practice there seems to be an unexplained race in that case - ScopedLock<Mutex> l(creditLock); - if (--readCredit == 0) { - assert(readCredit.get() >= 0); - if (readCredit.get() == 0) { - aio->stopReading(); - return false; - } - } - } - return true; + return ret; } void AsynchIOHandler::eof(AsynchIO&) { |