Return-Path: Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: (qmail 7157 invoked from network); 18 Sep 2009 19:56:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Sep 2009 19:56:10 -0000 Received: (qmail 67143 invoked by uid 500); 18 Sep 2009 19:56:10 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 67097 invoked by uid 500); 18 Sep 2009 19:56:10 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 67088 invoked by uid 99); 18 Sep 2009 19:56:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 19:56:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 19:56:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 23F6123888CD; Fri, 18 Sep 2009 19:55:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r816763 - /qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOHandler.cpp Date: Fri, 18 Sep 2009 19:55:48 -0000 To: commits@qpid.apache.org From: astitcher@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090918195548.23F6123888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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