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

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 909 bytes
Line 
1#include <filezilla.h>
2#include "rtt.h"
3
4CLatencyMeasurement::CLatencyMeasurement()
5{
6}
7
8int CLatencyMeasurement::GetLatency() const
9{
10        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        scoped_lock lock(m_sync);
20        if (m_start)
21                return false;
22
23        m_start = CMonotonicClock::now();
24
25        return true;
26}
27
28bool CLatencyMeasurement::Stop()
29{
30        scoped_lock lock(m_sync);
31        if (!m_start)
32                return false;
33
34        duration const diff = CMonotonicClock::now() - m_start;
35        m_start = CMonotonicClock();
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        scoped_lock lock(m_sync);
49        m_summed_latency = 0;
50        m_measurements = 0;
51        m_start = CMonotonicClock();
52}
53
54void CLatencyMeasurement::cb()
55{
56        Stop();
57}
Note: See TracBrowser for help on using the repository browser.