# HG changeset patch # User Alain Mazy # Date 1774030258 -3600 # Node ID 80e8dba83cdf7e1f998fe5092a914ee737d6ddff # Parent 6fd8630f295a5444d248d52ee0a07592b00c7795 fix metrics that could crash after 5 min of inactivity diff -r 6fd8630f295a -r 80e8dba83cdf Plugin/WeightedAverageMetrics.h --- a/Plugin/WeightedAverageMetrics.h Wed Mar 18 21:24:29 2026 +0100 +++ b/Plugin/WeightedAverageMetrics.h Fri Mar 20 19:10:58 2026 +0100 @@ -55,6 +55,7 @@ void RemoveOldest() { + // note: the mutex must be locked boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); if (values_.size() > 0) @@ -88,15 +89,8 @@ values_.push_back(Value(value, weight)); totalWeightedValue_ += value * weight; totalWeight_ += weight; - boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); - - const Value& oldest = values_.front(); - while ((now - oldest.time_).total_seconds() > duration_) - { - totalWeightedValue_ -= oldest.value_ * oldest.weight_; - totalWeight_ -= oldest.weight_; - values_.pop_front(); - } + + RemoveOldest(); } T GetAverage()