You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2009/05/25 18:41:28 UTC

svn commit: r778452 - in /qpid/trunk/qpid/cpp/src/qpid/broker: SemanticState.cpp SemanticState.h

Author: aconway
Date: Mon May 25 16:41:28 2009
New Revision: 778452

URL: http://svn.apache.org/viewvc?rev=778452&view=rev
Log:
ConsumerImpl optimization - use atomic value for queueHasMessages.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.h

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.cpp?rev=778452&r1=778451&r2=778452&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.cpp Mon May 25 16:41:28 2009
@@ -257,7 +257,7 @@
     msgCredit(0), 
     byteCredit(0),
     notifyEnabled(true),
-    queueHasMessages(true),
+    queueHasMessages(1),
     syncFrequency(_arguments.getAsInt("qpid.sync_frequency")),
     deliveryCount(0) {}
 
@@ -593,18 +593,11 @@
 
 bool SemanticState::ConsumerImpl::doOutput()
 {
-    {
-        Mutex::ScopedLock l(lock);
-        if (!haveCredit() || !queueHasMessages) return false;
-        queueHasMessages = false;
-    }
-    bool moreMessages = queue->dispatch(shared_from_this());
-    {
-        Mutex::ScopedLock l(lock);
-        // queueHasMessages may have been set by a notify() during dispatch()
-        queueHasMessages = queueHasMessages || moreMessages;
-    }
-    return queueHasMessages;
+    if (!haveCredit() || !queueHasMessages.boolCompareAndSwap(1, 0))
+        return false;
+    if (queue->dispatch(shared_from_this()))
+        queueHasMessages.boolCompareAndSwap(0, 1);
+    return queueHasMessages.get();
 }
 
 void SemanticState::ConsumerImpl::enableNotify()
@@ -626,10 +619,8 @@
 
 void SemanticState::ConsumerImpl::notify()
 {
-    {
-        Mutex::ScopedLock l(lock);
-        queueHasMessages = true;
-    }
+    queueHasMessages.boolCompareAndSwap(0, 1);
+
     //TODO: alter this, don't want to hold locks across external
     //calls; for now its is required to protect the notify() from
     //having part of the object chain of the invocation being

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.h?rev=778452&r1=778451&r2=778452&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/SemanticState.h Mon May 25 16:41:28 2009
@@ -77,8 +77,9 @@
         uint32_t msgCredit;
         uint32_t byteCredit;
         bool notifyEnabled;
-        //        sys::AtomicValue<bool> queueHasMessages;
-        bool queueHasMessages;
+        // queueHasMessages is boolean but valgrind has trouble with
+        // AtomicValue<bool> so use an int with 1 or 0.
+        sys:: AtomicValue<int> queueHasMessages; 
         const int syncFrequency;
         int deliveryCount;
 



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