From 2d846b7c8c6128d94aef3202564828d45b93908b Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 30 Apr 2024 15:37:35 +0000 Subject: [PATCH] Bug 1894147 - Fix C++20 std::memory_order build errors in MPSCQueue.h. r=xpcom-reviewers,emilio C++20 renamed the `std::memory_order::memory_order_*` enum constants to `std::memory_order::*`. https://en.cppreference.com/w/cpp/atomic/memory_order C++17 supports: `std::memory_order_relaxed` `std::memory_order::memory_order_relaxed` But C++20 supports: `std::memory_order_relaxed` `std::memory_order::memory_order::relaxed` Thus, `std::memory_order_relaxed` is the only shared name if we want to support compiling Firefox with -std=c++17 and -std=c++20 as we transition mozilla-central from C++17 to C++20. Differential Revision: https://phabricator.services.mozilla.com/D208963 --- mfbt/MPSCQueue.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mfbt/MPSCQueue.h b/mfbt/MPSCQueue.h index 8edd260344f5..a413fd63bcce 100644 --- a/mfbt/MPSCQueue.h +++ b/mfbt/MPSCQueue.h @@ -231,8 +231,7 @@ class MPSCRingBufferBase { * empty queue * */ void MarkSlot(std::atomic& aSlotStatus, uint64_t aIndex) { - uint64_t current = - aSlotStatus.load(std::memory_order::memory_order_relaxed); + uint64_t current = aSlotStatus.load(std::memory_order_relaxed); do { // Attempts to find a slot that is available to enqueue, without // cross-thread synchronization @@ -269,9 +268,9 @@ class MPSCRingBufferBase { // // In case of failure we require memory_order_relaxed for the load // operation because we dont need synchronization at that point. - if (aSlotStatus.compare_exchange_weak( - current, modified, std::memory_order::memory_order_release, - std::memory_order::memory_order_relaxed)) { + if (aSlotStatus.compare_exchange_weak(current, modified, + std::memory_order_release, + std::memory_order_relaxed)) { if constexpr (MPSC_DEBUG) { fprintf(stderr, "[enqueue] modified=0x%" PRIx64 " => index=%" PRIu64 "\n", @@ -297,8 +296,7 @@ class MPSCRingBufferBase { * */ [[nodiscard]] std::optional UnmarkSlot( std::atomic& aSlotStatus) { - uint64_t current = - aSlotStatus.load(std::memory_order::memory_order_relaxed); + uint64_t current = aSlotStatus.load(std::memory_order_relaxed); do { uint64_t index = current & mMask; if (index == 0) { @@ -318,9 +316,9 @@ class MPSCRingBufferBase { // // In case of failure we require memory_order_relaxed for the load // operation because we dont need synchronization at that point. - if (aSlotStatus.compare_exchange_weak( - current, modified, std::memory_order::memory_order_acquire, - std::memory_order::memory_order_relaxed)) { + if (aSlotStatus.compare_exchange_weak(current, modified, + std::memory_order_acquire, + std::memory_order_relaxed)) { if constexpr (MPSC_DEBUG) { fprintf(stderr, "[dequeue] current=0x%" PRIx64 " => index=%" PRIu64 "\n",