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 /logic/pipeline.cpp | |
parent | 9fd246a411e9faaf49c6b18c020fde351b9412a6 (diff) |
logic/pipeline: replace clunky atomic ops w/ a spinlock
Diffstat (limited to 'logic/pipeline.cpp')
-rw-r--r-- | logic/pipeline.cpp | 23 |
1 files changed, 10 insertions, 13 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); |