9 #ifndef INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_ 10 #define INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_ 34 static void ToTimespec(
const Value &value,
struct timespec *ret) {
35 ret->tv_sec = value / (1000 * 1000);
36 ret->tv_nsec = value % (1000 * 1000) * 1000;
41 return sec * 1000 * 1000;
59 clock_gettime(CLOCK_MONOTONIC, &now);
60 return now.tv_sec * 1000 * 1000 + now.tv_nsec / 1000;
80 class FUNAPI_DLL_VISIBILITY MonotonicClock {
83 typedef LONGLONG
Value;
89 static void ToTimespec(
const Value &value,
struct timespec *ret) {
90 ret->tv_sec = value / (1000 * 1000);
91 ret->tv_nsec = value % (1000 * 1000) * 1000;
95 static Duration FromSec(int64_t sec) {
96 return sec * 1000 * 1000;
100 static Duration FromMsec(int64_t msec) {
105 static Duration FromUsec(int64_t usec) {
113 static bool init =
false;
114 static LARGE_INTEGER frequency;
115 static LARGE_INTEGER epoch;
119 QueryPerformanceFrequency(&frequency);
120 QueryPerformanceCounter(&epoch);
124 QueryPerformanceCounter(&now);
127 diff.QuadPart = now.QuadPart - epoch.QuadPart;
131 diff.QuadPart *= 1000 * 1000;
132 diff.QuadPart /= frequency.QuadPart;
134 return diff.QuadPart;
145 #endif // INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_
static Duration FromSec(int64_t sec)
Converts sec value into Duration.
Definition: monotonic_clock.h:40
static Duration FromMsec(int64_t msec)
Converts msec value into Duration.
Definition: monotonic_clock.h:45
static Duration FromUsec(int64_t usec)
Converts usec value into Duration.
Definition: monotonic_clock.h:50
static void ToTimespec(const Value &value, struct timespec *ret)
Converts the given Monotonic clock value into timespec.
Definition: monotonic_clock.h:34
Funapi uses MonotonicClock to be overcome clock drift.
Definition: monotonic_clock.h:25
int64_t Duration
duration value in usec.
Definition: monotonic_clock.h:31
static Value Now()
Returns the current Monotonic value.
Definition: monotonic_clock.h:57
int64_t Value
clock value in usec.
Definition: monotonic_clock.h:28