Skip to content

Commit 5a143c7

Browse files
authored
Linux/MacOS: Use faster clock_gettime() for tick_cached() (#563)
1 parent fca7f5d commit 5a143c7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Common/precompiled.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include <filesystem>
7070
#include <memory>
7171
#include <chrono>
72+
#include <time.h>
7273
#include <regex>
7374
#include <type_traits>
7475
#include <optional>
@@ -362,8 +363,10 @@ bool match_any_of(T1 value, T2 compareTo, Types&&... others)
362363
const long long _Part = (_Ctr % _Freq) * std::nano::den / _Freq;
363364
return (std::chrono::steady_clock::time_point(std::chrono::nanoseconds(_Whole + _Part)));
364365
#else
365-
// todo: Add faster implementation for linux
366-
return std::chrono::steady_clock::now();
366+
struct timespec tp;
367+
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
368+
return std::chrono::steady_clock::time_point(
369+
std::chrono::seconds(tp.tv_sec) + std::chrono::nanoseconds(tp.tv_nsec));
367370
#endif
368371
}
369372

0 commit comments

Comments
 (0)