diff options
Diffstat (limited to 'cpp')
-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; |