From 63e1bb6605d78af73e52cc2ac38b46bd8d15c5f3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 5 Jun 2018 08:37:52 +0200 Subject: logic/pipeline: fix atomic ops No functional changes. Don't perform any atomic reads before compare-and-swap. The value read by CAS needs to go outside the loop. That's how CAS works. --- logic/pipeline.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'logic') diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index 4756db3e..c36d1781 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -642,14 +642,11 @@ void bits::set(flags flag_, bool val_) { const unsigned flag = unsigned(flag_); const unsigned val = unsigned(val_); + unsigned b_ = 0; 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)) + if (b.compare_exchange_strong(b_, unsigned((b_ & ~flag) | (flag * val)))) break; } } @@ -657,15 +654,11 @@ void bits::set(flags flag_, bool val_) void bits::negate(flags flag_) { const unsigned flag = unsigned(flag_); + unsigned b_ = 0; for (;;) { - unsigned b_(b); - - if (b.compare_exchange_weak(b_, - b_ ^ flag, - std::memory_order_seq_cst, - std::memory_order_seq_cst)) + if (b.compare_exchange_strong(b_, b_ ^ flag)) break; } } -- cgit v1.2.3