diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-12-29 13:32:06 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-16 07:48:19 +0100 |
commit | d6735a31fd37da160d690148efd896077f0a8f65 (patch) | |
tree | 6f19c3d391cc28cd97b4d273f755fa042dbbb2f7 | |
parent | 9fd246a411e9faaf49c6b18c020fde351b9412a6 (diff) |
logic/pipeline: replace clunky atomic ops w/ a spinlock
-rw-r--r-- | logic/pipeline.cpp | 23 | ||||
-rw-r--r-- | 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<unsigned> b; + bit_flags flags{0}; + std::atomic_flag lock = ATOMIC_FLAG_INIT; void set(bit_flags flag, bool val); void negate(bit_flags flag); |