From 69888e148e2d2056504387a17fa9889af991e31d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 15 Nov 2016 11:15:48 -0500 Subject: [PATCH] use correct latency computation --- Tunnel.cpp | 13 +++++++++---- Tunnel.h | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index 2d55547c..3e9bfc6b 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -23,18 +23,23 @@ namespace tunnel void TunnelLatency::AddSample(Sample s) { - m_samples ++; - m_latency += s / m_samples; + std::unique_lock l(m_access); + m_samples.push_back(s); } bool TunnelLatency::HasSamples() const { - return m_samples > 0; + std::unique_lock l(m_access); + return m_samples.size() > 0; } TunnelLatency::Latency TunnelLatency::GetMeanLatency() const { - return m_latency; + std::unique_lock l(m_access); + Latency l = 0; + for(auto s : m_samples) + l += s; + return l / m_samples.size(); } diff --git a/Tunnel.h b/Tunnel.h index 8712f56d..85590f58 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -90,9 +90,8 @@ namespace tunnel bool HasSamples() const; Latency GetMeanLatency() const; - Latency m_latency = 0; - std::size_t m_samples = 0; - + std::vector m_samples; + std::mutex m_access; }; class OutboundTunnel;