From 5a143c7b4b8929acf37a37b00c1068e8ab2d3251 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 8 Dec 2022 09:08:15 -0700 Subject: [PATCH] Linux/MacOS: Use faster clock_gettime() for tick_cached() (#563) --- src/Common/precompiled.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Common/precompiled.h b/src/Common/precompiled.h index 1eceaabd..dbfc5494 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -362,8 +363,10 @@ bool match_any_of(T1 value, T2 compareTo, Types&&... others) const long long _Part = (_Ctr % _Freq) * std::nano::den / _Freq; return (std::chrono::steady_clock::time_point(std::chrono::nanoseconds(_Whole + _Part))); #else - // todo: Add faster implementation for linux - return std::chrono::steady_clock::now(); + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC_RAW, &tp); + return std::chrono::steady_clock::time_point( + std::chrono::seconds(tp.tv_sec) + std::chrono::nanoseconds(tp.tv_nsec)); #endif }