3 #include "phonebook.hpp"
23 using _clock_period = std::nano;
24 using _clock_duration = std::chrono::duration<_clock_rep, _clock_period>;
28 using duration = _clock_duration;
30 time_point() =
default;
32 constexpr
explicit time_point(
const duration& time_since_epoch)
33 : _m_time_since_epoch{time_since_epoch} { }
35 [[nodiscard]] duration time_since_epoch()
const {
36 return _m_time_since_epoch;
39 time_point& operator+=(
const duration& d) {
40 this->_m_time_since_epoch += d;
44 time_point& operator-=(
const duration& d) {
45 this->_m_time_since_epoch -= d;
50 duration _m_time_since_epoch;
53 inline time_point::duration operator-(
const time_point& lhs,
const time_point& rhs) {
54 return lhs.time_since_epoch() - rhs.time_since_epoch();
57 inline time_point operator+(
const time_point& pt,
const time_point::duration& d) {
58 return time_point(pt.time_since_epoch() + d);
61 inline time_point operator+(
const time_point::duration& d,
const time_point& pt) {
62 return time_point(pt.time_since_epoch() + d);
65 inline bool operator<(
const time_point& lhs,
const time_point& rhs) {
66 return lhs.time_since_epoch() < rhs.time_since_epoch();
69 inline bool operator>(
const time_point& lhs,
const time_point& rhs) {
70 return lhs.time_since_epoch() > rhs.time_since_epoch();
73 inline bool operator<=(
const time_point& lhs,
const time_point& rhs) {
74 return lhs.time_since_epoch() <= rhs.time_since_epoch();
77 inline bool operator>=(
const time_point& lhs,
const time_point& rhs) {
78 return lhs.time_since_epoch() >= rhs.time_since_epoch();
81 inline bool operator==(
const time_point& lhs,
const time_point& rhs) {
82 return lhs.time_since_epoch() == rhs.time_since_epoch();
85 inline bool operator!=(
const time_point& lhs,
const time_point& rhs) {
86 return lhs.time_since_epoch() != rhs.time_since_epoch();
105 using period = _clock_period;
106 using duration = _clock_duration;
108 static constexpr
bool is_steady =
true;
109 static_assert(std::chrono::steady_clock::is_steady);
111 [[nodiscard]] time_point now()
const {
112 assert(this->
is_started() &&
"Can't call now() before this clock has been start()ed.");
113 return time_point{std::chrono::steady_clock::now() - _m_start};
116 int64_t absolute_ns(time_point relative) {
117 return std::chrono::nanoseconds{_m_start.time_since_epoch()}.count() +
118 std::chrono::nanoseconds{relative.time_since_epoch()}.count();
125 _m_start = std::chrono::steady_clock::now();
132 return _m_start > std::chrono::steady_clock::time_point{};
139 return time_point{_m_start.time_since_epoch()};
143 std::chrono::steady_clock::time_point _m_start;
146 using duration = RelativeClock::duration;
148 template<
typename unit = std::ratio<1>>
149 double duration2double(duration dur) {
150 return std::chrono::duration<double, unit>{dur}.count();
153 constexpr duration freq2period(
double fps) {
154 return duration{
static_cast<size_t>(std::chrono::nanoseconds{std::chrono::seconds{1}}.count() / fps)};
Relative clock for all of ILLIXR.
Definition: relative_clock.hpp:102
bool is_started() const
Check if the clock is started.
Definition: relative_clock.hpp:131
void start()
Starts the clock. All times are relative to this point.
Definition: relative_clock.hpp:124
time_point start_time() const
Get the start time of the clock.
Definition: relative_clock.hpp:138
A 'service' that can be registered in the phonebook.
Definition: phonebook.hpp:86
RAC_ERRNO_MSG.
Definition: data_format.hpp:15
long _clock_rep
Definition: relative_clock.hpp:22