From 9e5c2c20e36c1f0b29d8f184f9409dc671cf2c16 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 15 Apr 2026 10:23:04 -0400 Subject: [PATCH] Switch to std::atomic_flag. --- Concurrency/AsyncTaskQueue.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Concurrency/AsyncTaskQueue.hpp b/Concurrency/AsyncTaskQueue.hpp index c8ed04d43..a7e812965 100644 --- a/Concurrency/AsyncTaskQueue.hpp +++ b/Concurrency/AsyncTaskQueue.hpp @@ -124,7 +124,7 @@ public: /// The queue cannot be restarted; this is a destructive action. void stop() { if(thread_.joinable()) { - should_quit_.store(true, std::memory_order_relaxed); + should_quit_.test_and_set(std::memory_order_relaxed); enqueue([] {}); if constexpr (!perform_automatically) { perform(); @@ -166,17 +166,17 @@ public: /// until all scheduled work has been performed, placing a memory barrier /// in between. void spin_flush() { - std::atomic has_run = false; + std::atomic_flag has_run = ATOMIC_FLAG_INIT; enqueue([&has_run] () { - has_run.store(true, std::memory_order::release); + has_run.test_and_set(std::memory_order::release); }); if constexpr (!perform_automatically) { perform(); } - while(!has_run.load(std::memory_order::acquire)); + while(!has_run.test(std::memory_order::acquire)); } ~AsyncTaskQueue() { @@ -190,11 +190,11 @@ private: ActionVector actions; // Continue until told to quit. - while(!should_quit_.load(std::memory_order_relaxed)) { + while(!should_quit_.test(std::memory_order_relaxed)) { // Wait for new actions to be signalled, and grab them. std::unique_lock lock(condition_mutex_); condition_.wait(lock, [&] { - return !actions_.empty() || should_quit_.load(std::memory_order_relaxed); + return !actions_.empty() || should_quit_.test(std::memory_order_relaxed); }); std::swap(actions, actions_); lock.unlock(); @@ -218,7 +218,7 @@ private: ActionVector actions_; // Necessary synchronisation parts. - std::atomic should_quit_ = false; + std::atomic_flag should_quit_ = ATOMIC_FLAG_INIT; std::mutex condition_mutex_; std::condition_variable condition_;