From 163141255f74334d90f7612d77ec637efd5ae7f7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 10 Nov 2005 20:20:20 +0000 Subject: [PATCH] Include "timespec.h" rather than the sys/time / time business. (gethrxtime) [! (HAVE_NANOUPTIME || (defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME) || HAVE_MICROUPTIME)]: Fall back on gettime rather than rolling our own approximation. --- lib/gethrxtime.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/gethrxtime.c b/lib/gethrxtime.c index 2c985789dc..6ece8ae189 100644 --- a/lib/gethrxtime.c +++ b/lib/gethrxtime.c @@ -24,20 +24,12 @@ #include "gethrxtime.h" -#include -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif +#include "timespec.h" -/* Get the time of a high-resolution clock, preferably one that is not - subject to resetting or drifting. */ +/* Get the current time, as a count of the number of nanoseconds since + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ xtime_t gethrxtime (void) @@ -65,16 +57,14 @@ gethrxtime (void) return xtime_make (tv.tv_sec, 1000 * tv.tv_usec); } +# else /* No monotonically increasing clocks are available; fall back on a clock that might jump backwards, since it's the best we can do. */ -# elif HAVE_GETTIMEOFDAY && XTIME_PRECISION != 1 { - struct timeval tv; - gettimeofday (&tv, NULL); - return xtime_make (tv.tv_sec, 1000 * tv.tv_usec); + struct timespec ts; + gettime (&ts); + return xtime_make (ts.tv_sec, ts.tv_nsec); } -# else - return xtime_make (time (NULL), 0); # endif #endif } -- 2.47.3