From 6e77118706f81bd75a2ee8417749ff4783dcfb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjell=20Hedstr=C3=B6m?= Date: Tue, 28 Mar 2017 11:09:10 -0600 Subject: [PATCH] Time correction (#159) * Improved the cpackage build. Also removed test compilation warnings * To correcte what was reported in issue 155 (https://github.com/KjellKod/g3log/issues/155) --- src/time.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/time.cpp b/src/time.cpp index ee38dea..937e5d0 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -99,10 +99,18 @@ namespace g3 { // // Time stamps will later have system clock accuracy but relative times will have the precision // of the high resolution clock. - thread_local const auto os = - time_point_cast(system_clock::now()).time_since_epoch() - + thread_local const auto os_system = + time_point_cast(system_clock::now()).time_since_epoch(); + thread_local const auto os_high_resolution = time_point_cast(high_resolution_clock::now()).time_since_epoch(); - + thread_local auto os = os_system - os_high_resolution; + + // 32-bit system work-around, where apparenetly the os correction above could sometimes + // become negative. This correction will only be done once per thread + if (os.count() < 0 ) { + os = os_system; + } + auto now_ns = (time_point_cast(high_resolution_clock::now()).time_since_epoch() + os).count(); const auto kNanos = 1000000000; ts ->tv_sec = now_ns / kNanos;