summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2009-09-18 19:55:47 +0000
committerAndrew Stitcher <astitcher@apache.org>2009-09-18 19:55:47 +0000
commitd3c07faea48e2dbd57cf27fac2d9940ca6456a69 (patch)
treef6ec7549a915fe94a90c56b07c26d6330d75890b
parent5d2e5e2b890fa5c099158a63621803fd9ee08741 (diff)
downloadqpid-python-d3c07faea48e2dbd57cf27fac2d9940ca6456a69.tar.gz
Rearrange readCredit logic for correctness
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@816763 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp b/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp
index 8094abd43d..46d8f3b4f1 100644
--- a/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp
+++ b/qpid/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&) {