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/qpid/broker/SemanticState.cpp | |
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/qpid/broker/SemanticState.cpp')
-rw-r--r-- | cpp/src/qpid/broker/SemanticState.cpp | 25 |
1 files changed, 8 insertions, 17 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 |