19 #ifndef MIR_TIME_POSIX_TIMESTAMP_H_ 20 #define MIR_TIME_POSIX_TIMESTAMP_H_ 26 namespace mir {
namespace time {
44 : clock_id{CLOCK_MONOTONIC}, nanoseconds{0} {}
46 : clock_id{clk}, nanoseconds{ns} {}
48 : clock_id{clk}, nanoseconds{ts.tv_sec*1000000000LL + ts.tv_nsec} {}
53 clock_gettime(clock_id, &ts);
61 throw std::logic_error(
"Can't compare different time domains");
70 std::chrono::nanoseconds b)
83 std::chrono::nanoseconds b)
89 std::chrono::nanoseconds b)
91 return std::chrono::nanoseconds(a.
nanoseconds.count() % b.count());
122 ts.tv_sec = ns / 1000000000LL;
123 ts.tv_nsec = ns % 1000000000LL;
124 while (EINTR == clock_nanosleep(t.
clock_id, TIMER_ABSTIME, &ts, NULL)) {}
129 #endif // MIR_TIME_POSIX_TIMESTAMP_H_ AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: blob.h:26
static PosixTimestamp now(clockid_t clock_id)
Definition: posix_timestamp.h:50
PosixTimestamp(clockid_t clk, std::chrono::nanoseconds ns)
Definition: posix_timestamp.h:45
void assert_same_clock(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:58
PosixTimestamp(clockid_t clk, struct timespec const &ts)
Definition: posix_timestamp.h:47
PosixTimestamp()
Definition: posix_timestamp.h:43
clockid_t clock_id
Definition: posix_timestamp.h:40
std::chrono::nanoseconds nanoseconds
Definition: posix_timestamp.h:41
bool operator<(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:100
void sleep_until(PosixTimestamp const &t)
Definition: posix_timestamp.h:118
PosixTimestamp operator+(PosixTimestamp const &a, std::chrono::nanoseconds b)
Definition: posix_timestamp.h:82
bool operator>(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:94
bool operator<=(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:112
std::chrono::nanoseconds operator%(PosixTimestamp const &a, std::chrono::nanoseconds b)
Definition: posix_timestamp.h:88
PosixTimestamp operator-(PosixTimestamp const &a, std::chrono::nanoseconds b)
Definition: posix_timestamp.h:69
bool operator>=(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:106
Definition: posix_timestamp.h:38
bool operator==(PosixTimestamp const &a, PosixTimestamp const &b)
Definition: posix_timestamp.h:64