Author: astitcher
Date: Wed Mar 11 18:40:54 2009
New Revision: 752560

URL: http://svn.apache.org/viewvc?rev=752560&view=rev
Log:
Remove race condition in low level IO when throttling input
to avoid overloading the clustering service

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=752560&r1=752559&r2=752560&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp Wed Mar 11 18:40:54 
2009
@@ -84,10 +84,11 @@
     // Check whether we started in the don't about credit state
     if (readCredit.boolCompareAndSwap(InfiniteCredit, credit))
         return;
-    else if (readCredit.fetchAndAdd(credit) != 0)
-        return;
-    // Lock and retest credit to make sure we don't race with decreasing credit
+    // 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.fetchAndAdd(credit) != 0)
+        return;
     assert(readCredit.get() >= 0);
     if (readCredit.get() != 0)
         aio->startReading();
@@ -141,9 +142,10 @@
     }
     // 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) {
-            // Lock and retest credit to make sure we don't race with 
increasing credit
-            ScopedLock<Mutex> l(creditLock);
             assert(readCredit.get() >= 0);
             if (readCredit.get() == 0) {
                 aio->stopReading();



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

Reply via email to