diff --git a/core/src/gauge.cc b/core/src/gauge.cc index a52d103a..d54e19c7 100644 --- a/core/src/gauge.cc +++ b/core/src/gauge.cc @@ -14,16 +14,20 @@ void Gauge::Decrement() { Decrement(1.0); } void Gauge::Decrement(const double value) { Change(-1.0 * value); } -void Gauge::Set(const double value) { value_.store(value); } +void Gauge::Set(const double value) { + value_.store(value, std::memory_order_relaxed); +} void Gauge::Change(const double value) { #if __cpp_lib_atomic_float >= 201711L - value_.fetch_add(value); + value_.fetch_add(value, std::memory_order_relaxed); #else // Pre-C++ 20 fallback: busy loop (which might be more expansive than using // fetch_add). - auto current = value_.load(); - while (!value_.compare_exchange_weak(current, current + value)) { + auto current = value_.load(std::memory_order_relaxed); + while (!value_.compare_exchange_weak(current, current + value, + std::memory_order_relaxed, + std::memory_order_relaxed)) { // intentionally empty block } #endif