From 31ce79a7acd7d7667e20906e265d7451fa1c353f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 18 Nov 2016 20:56:59 +0100 Subject: logic/tracker: fix incorrect atomic bitmask usage --- logic/tracker.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'logic/tracker.cpp') diff --git a/logic/tracker.cpp b/logic/tracker.cpp index cfc62c84..61905837 100644 --- a/logic/tracker.cpp +++ b/logic/tracker.cpp @@ -449,25 +449,34 @@ void Tracker::get_raw_and_mapped_poses(double* mapped, double* raw) const void bits::set(bits::flags flag_, bool val_) { - unsigned b_(b); const unsigned flag = unsigned(flag_); - const unsigned val = unsigned(!!val_); - while (!b.compare_exchange_weak(b_, + const unsigned val = unsigned(val_); + + for (;;) + { + unsigned b_(b); + if (b.compare_exchange_weak(b_, unsigned((b_ & ~flag) | (flag * val)), std::memory_order_seq_cst, std::memory_order_seq_cst)) - { /* empty */ } + break; + } } void bits::negate(bits::flags flag_) { - unsigned b_(b); const unsigned flag = unsigned(flag_); - while (!b.compare_exchange_weak(b_, - (b_ & ~flag) | (flag & ~b_), + + for (;;) + { + unsigned b_(b); + + if (b.compare_exchange_weak(b_, + b_ ^ flag, std::memory_order_seq_cst, std::memory_order_seq_cst)) - { /* empty */ } + break; + } } bool bits::get(bits::flags flag) -- cgit v1.2.3