From d6735a31fd37da160d690148efd896077f0a8f65 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Dec 2018 13:32:06 +0100 Subject: logic/pipeline: replace clunky atomic ops w/ a spinlock --- logic/pipeline.cpp | 23 ++++++++++------------- logic/pipeline.hpp | 5 ++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index 4700bcc7..025ef456 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -601,31 +601,28 @@ void pipeline::toggle_enabled() { b.negate(f_enabled_p); } void bits::set(bit_flags flag, bool val) { - const unsigned flag_ = unsigned(flag); - const unsigned val_ = unsigned(val); - unsigned b_ = 0; + spinlock_guard l(lock); - for (;;) - if (b.compare_exchange_weak(b_, (b_ & ~flag_) | (flag_ * val_))) - break; + flags &= ~flag; + if (val) + flags |= flag; } void bits::negate(bit_flags flag) { - const unsigned flag_= flag; - unsigned b_ = 0; + spinlock_guard l(lock); - for (;;) - if (b.compare_exchange_weak(b_, b_ ^ flag_)) - break; + flags ^= flag; } bool bits::get(bit_flags flag) { - return !!(b & flag); + spinlock_guard l(lock); + + return !!(flags & flag); } -bits::bits() : b(0u) +bits::bits() { set(f_center, false); set(f_held_center, false); diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp index a4dcb6b8..bce0bd76 100644 --- a/logic/pipeline.hpp +++ b/logic/pipeline.hpp @@ -7,6 +7,7 @@ #include "mappings.hpp" #include "compat/euler.hpp" #include "compat/enum-operators.hpp" +#include "compat/spinlock.hpp" #include "runtime-libraries.hpp" #include "extensions.hpp" @@ -58,6 +59,7 @@ public: using namespace time_units; enum bit_flags : unsigned { + f_none = 0, f_center = 1 << 0, f_held_center = 1 << 1, f_enabled_h = 1 << 2, @@ -67,7 +69,8 @@ enum bit_flags : unsigned { struct OTR_LOGIC_EXPORT bits { - std::atomic b; + bit_flags flags{0}; + std::atomic_flag lock = ATOMIC_FLAG_INIT; void set(bit_flags flag, bool val); void negate(bit_flags flag); -- cgit v1.2.3