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
This commit is contained in:
Chris Peterson 2024-04-30 15:37:35 +00:00
parent ab9ee3940a
commit 2d846b7c8c

View File

@ -231,8 +231,7 @@ class MPSCRingBufferBase {
* empty queue * empty queue
* */ * */
void MarkSlot(std::atomic<uint64_t>& aSlotStatus, uint64_t aIndex) { void MarkSlot(std::atomic<uint64_t>& aSlotStatus, uint64_t aIndex) {
uint64_t current = uint64_t current = aSlotStatus.load(std::memory_order_relaxed);
aSlotStatus.load(std::memory_order::memory_order_relaxed);
do { do {
// Attempts to find a slot that is available to enqueue, without // Attempts to find a slot that is available to enqueue, without
// cross-thread synchronization // cross-thread synchronization
@ -269,9 +268,9 @@ class MPSCRingBufferBase {
// //
// In case of failure we require memory_order_relaxed for the load // In case of failure we require memory_order_relaxed for the load
// operation because we dont need synchronization at that point. // operation because we dont need synchronization at that point.
if (aSlotStatus.compare_exchange_weak( if (aSlotStatus.compare_exchange_weak(current, modified,
current, modified, std::memory_order::memory_order_release, std::memory_order_release,
std::memory_order::memory_order_relaxed)) { std::memory_order_relaxed)) {
if constexpr (MPSC_DEBUG) { if constexpr (MPSC_DEBUG) {
fprintf(stderr, fprintf(stderr,
"[enqueue] modified=0x%" PRIx64 " => index=%" PRIu64 "\n", "[enqueue] modified=0x%" PRIx64 " => index=%" PRIu64 "\n",
@ -297,8 +296,7 @@ class MPSCRingBufferBase {
* */ * */
[[nodiscard]] std::optional<uint64_t> UnmarkSlot( [[nodiscard]] std::optional<uint64_t> UnmarkSlot(
std::atomic<uint64_t>& aSlotStatus) { std::atomic<uint64_t>& aSlotStatus) {
uint64_t current = uint64_t current = aSlotStatus.load(std::memory_order_relaxed);
aSlotStatus.load(std::memory_order::memory_order_relaxed);
do { do {
uint64_t index = current & mMask; uint64_t index = current & mMask;
if (index == 0) { if (index == 0) {
@ -318,9 +316,9 @@ class MPSCRingBufferBase {
// //
// In case of failure we require memory_order_relaxed for the load // In case of failure we require memory_order_relaxed for the load
// operation because we dont need synchronization at that point. // operation because we dont need synchronization at that point.
if (aSlotStatus.compare_exchange_weak( if (aSlotStatus.compare_exchange_weak(current, modified,
current, modified, std::memory_order::memory_order_acquire, std::memory_order_acquire,
std::memory_order::memory_order_relaxed)) { std::memory_order_relaxed)) {
if constexpr (MPSC_DEBUG) { if constexpr (MPSC_DEBUG) {
fprintf(stderr, fprintf(stderr,
"[dequeue] current=0x%" PRIx64 " => index=%" PRIu64 "\n", "[dequeue] current=0x%" PRIx64 " => index=%" PRIu64 "\n",