-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathclock.hpp
59 lines (48 loc) · 1.31 KB
/
clock.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <chrono>
namespace kagome::clock {
/**
* An interface for a clock
* @tparam clock type is an underlying clock type, such as std::steady_clock
*/
template <typename ClockType>
class Clock {
public:
/**
* Difference between two time points
*/
using Duration = typename ClockType::duration;
/**
* A moment in time, stored in milliseconds since Unix epoch start
*/
using TimePoint = typename ClockType::time_point;
virtual ~Clock() = default;
/**
* @return a time point representing the current time
*/
virtual TimePoint now() const = 0;
/**
* @return uint64_t representing number of seconds since the beginning of
* epoch (Jan 1, 1970)
*/
virtual uint64_t nowUint64() const = 0;
static TimePoint zero() {
return TimePoint{};
}
};
/**
* SteadyClock alias over Clock. Should be used when we need to measure
* interval between two moments in time
*/
using SteadyClock = Clock<std::chrono::steady_clock>;
/**
* SystemClock alias over Clock. Should be used when we need to watch current
* time
*/
using SystemClock = Clock<std::chrono::system_clock>;
} // namespace kagome::clock