]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gethrxtime: don’t use nanouptime, microuptime master
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 20 Jun 2026 17:45:10 +0000 (10:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 20 Jun 2026 17:53:26 +0000 (10:53 -0700)
* lib/gethrxtime.c (gethrxtime): On platforms with
CLOCK_MONOTONIC, try it first.  If it fails, just fall back on
CLOCK_REALTIME as that’s what current_timespec would do anyway.
On platforms lacking CLOCK_MONOTONIC, just use current_timespec.
* m4/gethrxtime.m4 (gl_GETHRXTIME): Don’t check for microuptime or
nanouptime.  They aren’t exposed to user space by BSD kernels now,
and it’s not clear that they ever were.

ChangeLog
lib/gethrxtime.c
m4/gethrxtime.m4

index 6fd9e8ce3870fba0a0e1674481519b4ec11d77bd..6ee89378ea07f9cac6062ee067e87fed88b6f078 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2026-06-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+       gethrxtime: don’t use nanouptime, microuptime
+       * lib/gethrxtime.c (gethrxtime): On platforms with
+       CLOCK_MONOTONIC, try it first.  If it fails, just fall back on
+       CLOCK_REALTIME as that’s what current_timespec would do anyway.
+       On platforms lacking CLOCK_MONOTONIC, just use current_timespec.
+       * m4/gethrxtime.m4 (gl_GETHRXTIME): Don’t check for microuptime or
+       nanouptime.  They aren’t exposed to user space by BSD kernels now,
+       and it’s not clear that they ever were.
+
 2026-06-19  Paul Eggert  <eggert@cs.ucla.edu>
 
        fstatat: don’t mess with CFLAGS
index e1580b3d72d82c3a07164819edfdcaa7322055c6..72678b6f65e5028804bb7bd0adefc31a5ac9d4c0 100644 (file)
 xtime_t
 gethrxtime (void)
 {
-# if HAVE_NANOUPTIME
-  {
-    struct timespec ts;
-    nanouptime (&ts);
-    return xtime_make (ts.tv_sec, ts.tv_nsec);
-  }
+  struct timespec ts;
+# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
+  /* If available, use a monotonically increasing clock.
+     Otherwise fall back on CLOCK_REALTIME as that is
+     what current_timespec would do anyway.  */
+  if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
+    clock_gettime (CLOCK_REALTIME, &ts);
 # else
-
-#  if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
-  {
-    struct timespec ts;
-    if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
-      return xtime_make (ts.tv_sec, ts.tv_nsec);
-  }
-#  endif
-
-#  if HAVE_MICROUPTIME
-  {
-    struct timeval tv;
-    microuptime (&tv);
-    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.  */
-  {
-    struct timespec ts;
-    gettime (&ts);
-    return xtime_make (ts.tv_sec, ts.tv_nsec);
-  }
-#  endif
+  ts = current_timespec ();
 # endif
+  return xtime_make (ts.tv_sec, ts.tv_nsec);
 }
 
 #endif
index e141cfaef5b5e3b9b90d1ae8af66597b8cb94889..918437f8df38a36836fc6983e75fdc7774052c35 100644 (file)
@@ -20,10 +20,8 @@ AC_DEFUN([gl_GETHRXTIME],
     dnl Find libraries needed to link lib/gethrxtime.c.
     AC_REQUIRE([gl_CLOCK_TIME])
     AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-    AC_CHECK_FUNCS_ONCE([microuptime nanouptime])
-    if test $ac_cv_func_nanouptime != yes \
-       && { test $ac_cv_have_decl_gethrtime = no \
-            || test $gl_cv_arithmetic_hrtime_t = no; }; then
+    if { test $ac_cv_have_decl_gethrtime = no \
+         || test $gl_cv_arithmetic_hrtime_t = no; }; then
       AC_CACHE_CHECK([whether CLOCK_MONOTONIC or CLOCK_REALTIME is defined],
         [gl_cv_have_clock_gettime_macro],
         [AC_EGREP_CPP([have_clock_gettime_macro],