From 6512f0a46a6ced0d865faae14f0506278a39d819 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 10 Nov 2005 20:19:37 +0000 Subject: [PATCH] * modules/gethrxtime (Depends-on): Add gettime. * lib/gethrxtime.c: 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. * m4/gethrxtime.m4 (gl_PREREQ_GETHRXTIME): Don't require AC_HEADER_TIME or gettimeofday; no longer needed. --- ChangeLog | 4 ++++ lib/ChangeLog | 9 +++++++++ lib/gethrxtime.c | 28 +++++++++------------------- lib/gethrxtime.h | 5 +++-- m4/ChangeLog | 5 +++++ m4/gethrxtime.m4 | 5 ++--- modules/gethrxtime | 1 + 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5818d6080..9df774ad6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-11-10 Paul Eggert + + * modules/gethrxtime (Depends-on): Add gettime. + 2005-11-04 Bruno Haible * gnulib-tool: Implement --update mode. diff --git a/lib/ChangeLog b/lib/ChangeLog index a84cf1310..ec1a36749 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2005-11-10 Paul Eggert + + * gethrxtime.c: 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. + 2005-11-10 Simon Josefsson * readline.c: Remove EOL. diff --git a/lib/gethrxtime.c b/lib/gethrxtime.c index 2c985789d..6ece8ae18 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 } diff --git a/lib/gethrxtime.h b/lib/gethrxtime.h index ecbd505d5..2247f968d 100644 --- a/lib/gethrxtime.h +++ b/lib/gethrxtime.h @@ -24,8 +24,9 @@ # include "xtime.h" /* Get the current time, as a count of the number of nanoseconds since - an arbitrary epoch (e.g., the system boot time). This clock can't - be set, is always increasing, and is nearly linear. */ + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ # if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME # include diff --git a/m4/ChangeLog b/m4/ChangeLog index 471f2fd87..b797738de 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,8 @@ +2005-11-10 Paul Eggert + + * gethrxtime.m4 (gl_PREREQ_GETHRXTIME): Don't require AC_HEADER_TIME + or gettimeofday; no longer needed. + 2005-10-30 Paul Eggert * chdir-long.m4 (gl_FUNC_CHDIR_LONG): Revamp wording and local diff --git a/m4/gethrxtime.m4 b/m4/gethrxtime.m4 index 82ca6280e..2b6fe367c 100644 --- a/m4/gethrxtime.m4 +++ b/m4/gethrxtime.m4 @@ -1,4 +1,4 @@ -# gethrxtime.m4 serial 2 +# gethrxtime.m4 serial 3 dnl Copyright (C) 2005 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -50,10 +50,9 @@ AC_DEFUN([gl_XTIME], # Prerequisites of lib/gethrxtime.c. AC_DEFUN([gl_PREREQ_GETHRXTIME], [ - AC_REQUIRE([AC_HEADER_TIME]) AC_REQUIRE([gl_CLOCK_TIME]) AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_FUNCS_ONCE(gettimeofday microuptime nanouptime) + AC_CHECK_FUNCS_ONCE(microuptime nanouptime) if test $ac_cv_func_nanouptime != yes; then LIB_GETHRXTIME= diff --git a/modules/gethrxtime b/modules/gethrxtime index b09ec2c33..8c40d28f0 100644 --- a/modules/gethrxtime +++ b/modules/gethrxtime @@ -10,6 +10,7 @@ m4/clock_time.m4 m4/longlong.m4 Depends-on: +gettime extensions configure.ac: -- 2.11.0