From 173bfa66f72d70dabe9a8b3e9cc18796de06bfa6 Mon Sep 17 00:00:00 2001 From: Micke632 Date: Fri, 24 Oct 2025 10:43:50 +0200 Subject: [PATCH] atomic_flag_bool new struct atomic_flag_bool atomic on/off flag variable --- include/itlib/atomic.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/itlib/atomic.hpp b/include/itlib/atomic.hpp index 1f757ee..1c31ce5 100644 --- a/include/itlib/atomic.hpp +++ b/include/itlib/atomic.hpp @@ -87,4 +87,32 @@ struct atomic_relaxed_counter { } }; +struct atomic_flag_bool { + + std::atomic_bool a{ true }; + + atomic_flag_bool() noexcept = default; + explicit atomic_flag_bool(bool init) noexcept { + set(init); + } + + void set(bool value) noexcept { + a.store(value, std::memory_order_release); + } + + atomic_flag_bool& operator=(bool i) { + set(i); + return *this; + } + + operator bool() const noexcept { + return get(); + } + + bool get() const noexcept { + return a.load(std::memory_order_acquire); + } +}; + + }