diff options
author | Alan Conway <aconway@apache.org> | 2009-05-25 16:41:28 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-05-25 16:41:28 +0000 |
commit | 21dd878012fad826d335bc8aa7d9e9b88da7d6ff (patch) | |
tree | b77b64cba54ca95041c4a6c13aaee72880d76103 /cpp/src | |
parent | 2d5c06afc92328e4f63ccfde192c7bc786d543fc (diff) | |
download | qpid-python-21dd878012fad826d335bc8aa7d9e9b88da7d6ff.tar.gz |
ConsumerImpl optimization - use atomic value for queueHasMessages.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@778452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/SemanticState.cpp | 25 | ||||
-rw-r--r-- | cpp/src/qpid/broker/SemanticState.h | 5 |
2 files changed, 11 insertions, 19 deletions
diff --git a/cpp/src/qpid/broker/SemanticState.cpp b/cpp/src/qpid/broker/SemanticState.cpp index 22908afd8e..8f918ff40f 100644 --- a/cpp/src/qpid/broker/SemanticState.cpp +++ b/cpp/src/qpid/broker/SemanticState.cpp @@ -257,7 +257,7 @@ SemanticState::ConsumerImpl::ConsumerImpl(SemanticState* _parent, 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::hasOutput() { 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 @@ bool SemanticState::ConsumerImpl::isNotifyEnabled() const { 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 diff --git a/cpp/src/qpid/broker/SemanticState.h b/cpp/src/qpid/broker/SemanticState.h index 8237f22e3f..a69962c083 100644 --- a/cpp/src/qpid/broker/SemanticState.h +++ b/cpp/src/qpid/broker/SemanticState.h @@ -77,8 +77,9 @@ class SemanticState : public sys::OutputTask, 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; |