Switch atomic_flag to atomic_bool

The constructor for atomic_flag is challenging to use in a constexpr.
It requires

   std::atomic_flag flag = ATOMIC_FLAG_INIT;

which is not constexpr on some compilers in C++20.

Switching to atomic_bool solves this problem.
This commit is contained in:
Matthew Parkinson
2022-03-18 14:50:58 +00:00
committed by Matthew Parkinson
parent a022a75b91
commit a3c8abc3c3
2 changed files with 11 additions and 15 deletions

View File

@@ -142,10 +142,10 @@ namespace snmalloc
void check(uint64_t time_ms)
{
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
static std::atomic_bool lock{false};
// Depulicate calls into here, and make single threaded.
if (lock.test_and_set())
// Deduplicate calls into here, and make single threaded.
if (lock.exchange(true, std::memory_order_acquire))
return;
timers.apply_all([time_ms](PalTimerObject* curr) {
@@ -156,7 +156,8 @@ namespace snmalloc
curr->pal_notify(curr);
}
});
lock.clear();
lock.store(false, std::memory_order_release);
}
};
} // namespace snmalloc