You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2009/09/18 21:55:48 UTC

svn commit: r816763 - /qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp

Author: astitcher
Date: Fri Sep 18 19:55:47 2009
New Revision: 816763

URL: http://svn.apache.org/viewvc?rev=816763&view=rev
Log:
Rearrange readCredit logic for correctness

Modified:
    qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp?rev=816763&r1=816762&r2=816763&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp Fri Sep 18 19:55:47 2009
@@ -107,6 +107,23 @@
     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 @@
         // 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&) {



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org