diff --git a/monitoring/histogram.cc b/monitoring/histogram.cc index 56b5a3914a..083ef75fdf 100644 --- a/monitoring/histogram.cc +++ b/monitoring/histogram.cc @@ -105,17 +105,26 @@ void HistogramStat::Add(uint64_t value) { // by concurrent threads is tolerable. const size_t index = bucketMapper.IndexForValue(value); assert(index < num_buckets_); - buckets_[index].fetch_add(1, std::memory_order_relaxed); + buckets_[index].store(buckets_[index].load(std::memory_order_relaxed) + 1, + std::memory_order_relaxed); uint64_t old_min = min(); - while (value < old_min && !min_.compare_exchange_weak(old_min, value)) {} + if (value < old_min) { + min_.store(value, std::memory_order_relaxed); + } uint64_t old_max = max(); - while (value > old_max && !max_.compare_exchange_weak(old_max, value)) {} + if (value > old_max) { + max_.store(value, std::memory_order_relaxed); + } - num_.fetch_add(1, std::memory_order_relaxed); - sum_.fetch_add(value, std::memory_order_relaxed); - sum_squares_.fetch_add(value * value, std::memory_order_relaxed); + num_.store(num_.load(std::memory_order_relaxed) + 1, + std::memory_order_relaxed); + sum_.store(sum_.load(std::memory_order_relaxed) + value, + std::memory_order_relaxed); + sum_squares_.store( + sum_squares_.load(std::memory_order_relaxed) + value * value, + std::memory_order_relaxed); } void HistogramStat::Merge(const HistogramStat& other) {