Skip to content

Commit d863f10

Browse files
authored
Update concurrentqueue.h
fix issue cameron314#404
1 parent 6dd38b8 commit d863f10

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

concurrentqueue.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ class ConcurrentQueue
14931493
assert((head->freeListRefs.load(std::memory_order_relaxed) & SHOULD_BE_ON_FREELIST) == 0);
14941494

14951495
// Decrease refcount twice, once for our ref, and once for the list's ref
1496-
head->freeListRefs.fetch_sub(2, std::memory_order_release);
1496+
head->freeListRefs.fetch_sub(2, std::memory_order_acq_rel);
14971497
return head;
14981498
}
14991499

@@ -1529,7 +1529,7 @@ class ConcurrentQueue
15291529
node->freeListRefs.store(1, std::memory_order_release);
15301530
if (!freeListHead.compare_exchange_strong(head, node, std::memory_order_release, std::memory_order_relaxed)) {
15311531
// Hmm, the add failed, but we can only try again when the refcount goes back to zero
1532-
if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST - 1, std::memory_order_release) == 1) {
1532+
if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST - 1, std::memory_order_acq_rel) == 1) {
15331533
continue;
15341534
}
15351535
}
@@ -1604,7 +1604,7 @@ class ConcurrentQueue
16041604
}
16051605
else {
16061606
// Increment counter
1607-
auto prevVal = elementsCompletelyDequeued.fetch_add(1, std::memory_order_release);
1607+
auto prevVal = elementsCompletelyDequeued.fetch_add(1, std::memory_order_acq_rel);
16081608
assert(prevVal < BLOCK_SIZE);
16091609
return prevVal == BLOCK_SIZE - 1;
16101610
}
@@ -1627,7 +1627,7 @@ class ConcurrentQueue
16271627
}
16281628
else {
16291629
// Increment counter
1630-
auto prevVal = elementsCompletelyDequeued.fetch_add(count, std::memory_order_release);
1630+
auto prevVal = elementsCompletelyDequeued.fetch_add(count, std::memory_order_acq_rel);
16311631
assert(prevVal + count <= BLOCK_SIZE);
16321632
return prevVal + count == BLOCK_SIZE;
16331633
}
@@ -2044,7 +2044,7 @@ class ConcurrentQueue
20442044
}
20452045
else {
20462046
// Wasn't anything to dequeue after all; make the effective dequeue count eventually consistent
2047-
this->dequeueOvercommit.fetch_add(1, std::memory_order_release); // Release so that the fetch_add on dequeueOptimisticCount is guaranteed to happen before this write
2047+
this->dequeueOvercommit.fetch_add(1, std::memory_order_acq_rel); // Release so that the fetch_add on dequeueOptimisticCount is guaranteed to happen before this write
20482048
}
20492049
}
20502050

@@ -2261,7 +2261,7 @@ class ConcurrentQueue
22612261
if (details::circular_less_than<size_t>(0, actualCount)) {
22622262
actualCount = desiredCount < actualCount ? desiredCount : actualCount;
22632263
if (actualCount < desiredCount) {
2264-
this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release);
2264+
this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_acq_rel);
22652265
}
22662266

22672267
// Get the first index. Note that since there's guaranteed to be at least actualCount elements, this
@@ -2330,7 +2330,7 @@ class ConcurrentQueue
23302330
}
23312331
else {
23322332
// Wasn't anything to dequeue after all; make the effective dequeue count eventually consistent
2333-
this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release);
2333+
this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_acq_rel);
23342334
}
23352335
}
23362336

@@ -2611,7 +2611,7 @@ class ConcurrentQueue
26112611
return true;
26122612
}
26132613
else {
2614-
this->dequeueOvercommit.fetch_add(1, std::memory_order_release);
2614+
this->dequeueOvercommit.fetch_add(1, std::memory_order_acq_rel);
26152615
}
26162616
}
26172617

@@ -2793,7 +2793,7 @@ class ConcurrentQueue
27932793
if (details::circular_less_than<size_t>(0, actualCount)) {
27942794
actualCount = desiredCount < actualCount ? desiredCount : actualCount;
27952795
if (actualCount < desiredCount) {
2796-
this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release);
2796+
this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_acq_rel);
27972797
}
27982798

27992799
// Get the first index. Note that since there's guaranteed to be at least actualCount elements, this
@@ -2871,7 +2871,7 @@ class ConcurrentQueue
28712871
return actualCount;
28722872
}
28732873
else {
2874-
this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release);
2874+
this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_acq_rel);
28752875
}
28762876
}
28772877

@@ -3452,7 +3452,7 @@ class ConcurrentQueue
34523452
auto newCount = 1 + implicitProducerHashCount.fetch_add(1, std::memory_order_relaxed);
34533453
while (true) {
34543454
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
3455-
if (newCount >= (mainHash->capacity >> 1) && !implicitProducerHashResizeInProgress.test_and_set(std::memory_order_acquire)) {
3455+
if (newCount >= (mainHash->capacity >> 1) && !implicitProducerHashResizeInProgress.test_and_set(std::memory_order_acq_rel)) {
34563456
// We've acquired the resize lock, try to allocate a bigger hash table.
34573457
// Note the acquire fence synchronizes with the release fence at the end of this block, and hence when
34583458
// we reload implicitProducerHash it must be the most recent version (it only gets changed within this
@@ -3702,15 +3702,15 @@ template<typename T, typename Traits>
37023702
ConsumerToken::ConsumerToken(ConcurrentQueue<T, Traits>& queue)
37033703
: itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr)
37043704
{
3705-
initialOffset = queue.nextExplicitConsumerId.fetch_add(1, std::memory_order_release);
3705+
initialOffset = queue.nextExplicitConsumerId.fetch_add(1, std::memory_order_acq_rel);
37063706
lastKnownGlobalOffset = static_cast<std::uint32_t>(-1);
37073707
}
37083708

37093709
template<typename T, typename Traits>
37103710
ConsumerToken::ConsumerToken(BlockingConcurrentQueue<T, Traits>& queue)
37113711
: itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr)
37123712
{
3713-
initialOffset = reinterpret_cast<ConcurrentQueue<T, Traits>*>(&queue)->nextExplicitConsumerId.fetch_add(1, std::memory_order_release);
3713+
initialOffset = reinterpret_cast<ConcurrentQueue<T, Traits>*>(&queue)->nextExplicitConsumerId.fetch_add(1, std::memory_order_acq_rel);
37143714
lastKnownGlobalOffset = static_cast<std::uint32_t>(-1);
37153715
}
37163716

0 commit comments

Comments
 (0)