Fix timespec

This commit is contained in:
Kamil Trzcinski
2022-04-06 13:54:28 +02:00
parent 568a44a372
commit e8aa94e4f4
3 changed files with 8 additions and 6 deletions

View File

@ -86,9 +86,10 @@ uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, i
clock_gettime(clock, &now);
if (delays_us > 0) {
now.tv_nsec += delays_us * 1000LL;
now.tv_sec += now.tv_nsec / (1000LL * 1000LL * 1000LL);
now.tv_nsec %= 1000LL * 1000LL * 1000LL;
#define NS_IN_S (1000LL * 1000LL * 1000LL)
int64_t nsec = now.tv_nsec + delays_us * 1000LL;
now.tv_nsec = nsec % NS_IN_S;
now.tv_sec += nsec / NS_IN_S;
}
if (ts) {