summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/time.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h
index 3fdc7d43ea8..288922d8a83 100644
--- a/src/vppinfra/time.h
+++ b/src/vppinfra/time.h
@@ -263,10 +263,12 @@ unix_usage_now (void)
always_inline void
unix_sleep (f64 dt)
{
- struct timespec t;
- t.tv_sec = dt;
- t.tv_nsec = 1e9 * dt;
- nanosleep (&t, 0);
+ struct timespec ts, tsrem;
+ ts.tv_sec = dt;
+ ts.tv_nsec = 1e9 * (dt - (f64) ts.tv_sec);
+
+ while (nanosleep (&ts, &tsrem) < 0)
+ ts = tsrem;
}
#else /* ! CLIB_UNIX */