source: filezilla/trunk/fuentes/src/engine/rtt.cpp @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 2 years ago

Update new version: 3.15.02

File size: 945 bytes
Line 
1#include <filezilla.h>
2#include "rtt.h"
3
4CLatencyMeasurement::CLatencyMeasurement()
5{
6}
7
8int CLatencyMeasurement::GetLatency() const
9{
10        fz::scoped_lock lock(m_sync);
11        if (!m_measurements)
12                return -1;
13
14        return static_cast<int>(m_summed_latency / m_measurements);
15}
16
17bool CLatencyMeasurement::Start()
18{
19        fz::scoped_lock lock(m_sync);
20        if (m_start)
21                return false;
22
23        m_start = fz::monotonic_clock::now();
24
25        return true;
26}
27
28bool CLatencyMeasurement::Stop()
29{
30        fz::scoped_lock lock(m_sync);
31        if (!m_start)
32                return false;
33
34        fz::duration const diff = fz::monotonic_clock::now() - m_start;
35        m_start = fz::monotonic_clock();
36
37        if (diff.get_milliseconds() < 0)
38                return false;
39
40        m_summed_latency += diff.get_milliseconds();
41        ++m_measurements;
42
43        return true;
44}
45
46void CLatencyMeasurement::Reset()
47{
48        fz::scoped_lock lock(m_sync);
49        m_summed_latency = 0;
50        m_measurements = 0;
51        m_start = fz::monotonic_clock();
52}
53
54void CLatencyMeasurement::cb()
55{
56        Stop();
57}
Note: See TracBrowser for help on using the repository browser.