Make sure the nano second part is less than one second. This matches
what clock_settime expects and allows for more concise kernel
interfaces.
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
Reviewed-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3534>
clock_gettime(CLOCK_MONOTONIC, &t);
tv->tv_sec = t.tv_sec + ns / NSEC_PER_SEC;
tv->tv_nsec = t.tv_nsec + ns % NSEC_PER_SEC;
+ if (tv->tv_nsec >= NSEC_PER_SEC) {
+ tv->tv_nsec -= NSEC_PER_SEC;
+ tv->tv_sec++;
+ }
}
#if HAVE_VALGRIND