Skip to content

Commit

Permalink
Time correction (#159)
Browse files Browse the repository at this point in the history
* Improved the cpackage build. Also removed test compilation warnings

* To correcte what was reported in issue 155 (#155)
  • Loading branch information
Kjell Hedström authored Mar 28, 2017
1 parent 417ae2c commit 6e77118
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nanoseconds>(system_clock::now()).time_since_epoch() -
thread_local const auto os_system =
time_point_cast<nanoseconds>(system_clock::now()).time_since_epoch();
thread_local const auto os_high_resolution =
time_point_cast<nanoseconds>(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<nanoseconds>(high_resolution_clock::now()).time_since_epoch() + os).count();
const auto kNanos = 1000000000;
ts ->tv_sec = now_ns / kNanos;
Expand Down

0 comments on commit 6e77118

Please sign in to comment.