Skip to content

Commit 76e2aec

Browse files
Fix rollover nanoseconds (#438) (#440)
(cherry picked from commit 3e314f3) Co-authored-by: Antonio Cuadros <[email protected]>
1 parent c74c6d5 commit 76e2aec

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/default_transport.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ extern "C"
1818
{
1919
(void)unused;
2020
static uint32_t rollover = 0;
21-
static uint64_t last_measure = 0;
21+
static uint32_t last_measure = 0;
2222

23-
uint64_t m = micros();
24-
tp->tv_sec = m / 1000000;
25-
tp->tv_nsec = (m % 1000000) * 1000;
26-
27-
// Rollover handling
23+
uint32_t m = micros();
2824
rollover += (m < last_measure) ? 1 : 0;
29-
uint64_t rollover_extra_us = rollover * micro_rollover_useconds;
30-
tp->tv_sec += rollover_extra_us / 1000000;
31-
tp->tv_nsec += (rollover_extra_us % 1000000) * 1000;
25+
26+
uint64_t real_us = (uint64_t) (m + rollover * micro_rollover_useconds);
27+
tp->tv_sec = real_us / 1000000;
28+
tp->tv_nsec = (real_us % 1000000) * 1000;
3229
last_measure = m;
3330

3431
return 0;

0 commit comments

Comments
 (0)