From 939a7f7eae0965cc26f2413e314b3ce9de908691 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 12 Dec 2022 22:49:32 +0000 Subject: [PATCH] Move std::atomic_flag to std::atomic C++20 accidentally deprecated ATOMIC_FLAG_INIT, but in C++17 this is the only way to reliably initialize an atomic_flag to a known value. See https://en.cppreference.com/w/cpp/atomic/ATOMIC_FLAG_INIT --- src/snmalloc/ds/aba.h | 6 +++--- src/snmalloc/mem/pooled.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/snmalloc/ds/aba.h b/src/snmalloc/ds/aba.h index 51c4470..f14cc9e 100644 --- a/src/snmalloc/ds/aba.h +++ b/src/snmalloc/ds/aba.h @@ -141,7 +141,7 @@ namespace snmalloc class ABA { std::atomic ptr = nullptr; - std::atomic_flag lock = ATOMIC_FLAG_INIT; + std::atomic lock{false}; public: // This method is used in Verona @@ -154,7 +154,7 @@ namespace snmalloc Cmp read() { - while (lock.test_and_set(std::memory_order_acquire)) + while (lock.exchange(true, std::memory_order_acquire)) Aal::pause(); # if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) @@ -184,7 +184,7 @@ namespace snmalloc ~Cmp() { - parent->lock.clear(std::memory_order_release); + parent->lock.store(false, std::memory_order_release); # if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) operation_in_flight = false; # endif diff --git a/src/snmalloc/mem/pooled.h b/src/snmalloc/mem/pooled.h index 51fc351..086cd22 100644 --- a/src/snmalloc/mem/pooled.h +++ b/src/snmalloc/mem/pooled.h @@ -24,25 +24,25 @@ namespace snmalloc std::atomic next{nullptr}; /// Used by the pool to keep the list of all entries ever created. capptr::Alloc list_next; - std::atomic_flag in_use = ATOMIC_FLAG_INIT; + std::atomic in_use{false}; public: void set_in_use() { - if (in_use.test_and_set()) + if (in_use.exchange(true)) error("Critical error: double use of Pooled Type!"); } void reset_in_use() { - in_use.clear(); + in_use.store(false); } bool debug_is_in_use() { - bool result = in_use.test_and_set(); + bool result = in_use.exchange(true); if (!result) - in_use.clear(); + in_use.store(false); return result; } };