mirror of
https://github.com/KjellKod/g3log.git
synced 2025-03-01 10:57:57 +01:00
fix timing inaccuracy on windows
This commit is contained in:
parent
813e3da1f9
commit
069085c451
@ -100,7 +100,14 @@ namespace g3 {
|
||||
ts->tv_nsec = now.tv_usec * 1000;
|
||||
return 0;
|
||||
#elif(defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
|
||||
return timespec_get(ts, TIME_UTC);
|
||||
static auto os =
|
||||
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now()).time_since_epoch() -
|
||||
std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch();
|
||||
|
||||
auto now_ns = (std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch() + os).count();
|
||||
ts ->tv_sec = now_ns / 1000000000;
|
||||
ts ->tv_nsec = now_ns % 1000000000;
|
||||
return TIME_UTC;
|
||||
#else
|
||||
// ubuntu/gcc5 has no support for std::timespec_get(...) as of yet
|
||||
return clock_gettime(CLOCK_REALTIME, ts);
|
||||
|
Loading…
x
Reference in New Issue
Block a user