27 inline uint64_t as_nanoseconds(
const struct timespec& ts)
29 return ts.tv_sec *
static_cast<uint64_t
>(1000000000L) + ts.tv_nsec;
31 inline void from_nanoseconds(
const uint64_t ns,
struct timespec& ts)
33 ts.tv_sec = (ns /
static_cast<uint64_t
>(1000000000L));
34 ts.tv_nsec = (ns %
static_cast<uint64_t
>(1000000000L));
50 GetSystemTimeAsFileTime(&t);
51 return (((uint64_t)t.dwHighDateTime) << 32) | ((uint64_t)t.dwLowDateTime);
53 #if defined(__APPLE__)
56 gettimeofday(&tv,
nullptr);
57 tim.tv_sec = tv.tv_sec;
58 tim.tv_nsec = tv.tv_usec * 1000;
64 case mrpt::Clock::Source::Realtime:
67 clock_gettime(CLOCK_REALTIME, &tim);
70 case mrpt::Clock::Source::Monotonic:
78 clock_gettime(CLOCK_MONOTONIC, &tim);
82 from_nanoseconds(
sum, tim);
89 return uint64_t(tim.tv_sec) * UINT64_C(10000000) +
90 UINT64_C(116444736) * UINT64_C(1000000000) + tim.tv_nsec / 100;
102 uint64_t(t * 10000000.0) + UINT64_C(116444736) * UINT64_C(1000000000)));
109 t.time_since_epoch().count() -
110 UINT64_C(116444736) * UINT64_C(1000000000)) /
117 s == mrpt::Clock::Source::Realtime ||
118 s == mrpt::Clock::Source::Monotonic);
127 timespec tim_rt{0, 0}, tim_mono{0, 0};
128 clock_gettime(CLOCK_REALTIME, &tim_rt);
129 clock_gettime(CLOCK_MONOTONIC, &tim_mono);
137 std::cerr <<
"[mrpt::Clock::resetMonotonicToRealTimeEpoch] CRITICAL: "
138 "Unreliable values: realtime_ns="
140 <<
" should be larger than monotonic_ns="
147 static_cast<int64_t
>(old_diff))