Move std::atomic_flag to std::atomic<bool>

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
This commit is contained in:
Nathaniel Wesley Filardo
2022-12-12 22:49:32 +00:00
committed by Nathaniel Filardo
parent 524579eea1
commit 939a7f7eae
2 changed files with 8 additions and 8 deletions

View File

@@ -141,7 +141,7 @@ namespace snmalloc
class ABA
{
std::atomic<T*> ptr = nullptr;
std::atomic_flag lock = ATOMIC_FLAG_INIT;
std::atomic<bool> 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

View File

@@ -24,25 +24,25 @@ namespace snmalloc
std::atomic<T*> next{nullptr};
/// Used by the pool to keep the list of all entries ever created.
capptr::Alloc<T> list_next;
std::atomic_flag in_use = ATOMIC_FLAG_INIT;
std::atomic<bool> 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;
}
};