Check the availability of host_get_time64 and use it to replace
host_get_time for CLOCK_REALTIME when it's available.

host_get_time is deprecated
See 
https://git.savannah.gnu.org/cgit/hurd/gnumach.git/commit/?id=569df850cd7badd1e36132ad3b44aa76a4d27c25
However, it's kept for backward compactbility.

* config.h.in: Add HAVE_HOST_GET_TIME64 config entry
* sysdeps/mach/clock_gettime.c: Use host_get_time64 for CLOCK_REALTIME
  when it's possible
* sysdeps/mach/configure: Check the existence of host_get_time64 RPC
* sysdeps/mach/configure.ac: Check the existence of host_get_time64 RPC
---
 config.h.in                  |  3 +++
 sysdeps/mach/clock_gettime.c |  8 +++++++-
 sysdeps/mach/configure       | 30 ++++++++++++++++++++++++++++++
 sysdeps/mach/configure.ac    |  2 ++
 4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/config.h.in b/config.h.in
index cdbd5553..d3575c98 100644
--- a/config.h.in
+++ b/config.h.in
@@ -166,6 +166,9 @@
 /* Mach specific: define if the `host_get_uptime64' RPC is available.  */
 #undef HAVE_HOST_GET_UPTIME64
 
+/* Mach specific: define if the `host_get_time64' RPC is available.  */
+#undef HAVE_HOST_GET_TIME64
+
 /* Mach specific: define if the `thread_set_name' RPC is available.  */
 #undef  HAVE_MACH_THREAD_SET_NAME
 
diff --git a/sysdeps/mach/clock_gettime.c b/sysdeps/mach/clock_gettime.c
index 381ccb84..515f887e 100644
--- a/sysdeps/mach/clock_gettime.c
+++ b/sysdeps/mach/clock_gettime.c
@@ -57,13 +57,19 @@ __clock_gettime (clockid_t clock_id, struct timespec *ts)
 
     case CLOCK_REALTIME:
       {
-       /* __host_get_time can only fail if passed an invalid host_t.
+       /* __host_get_time(64) can only fail if passed an invalid host_t.
           __mach_host_self could theoretically fail (producing an
           invalid host_t) due to resource exhaustion, but we assume
           this will never happen.  */
+#ifdef HAVE_HOST_GET_TIME64
+       time_value64_t tv;
+       __host_get_time64 (__mach_host_self (), &tv);
+       TIME_VALUE64_TO_TIMESPEC (&tv, ts);
+#else
        time_value_t tv;
        __host_get_time (__mach_host_self (), &tv);
        TIME_VALUE_TO_TIMESPEC (&tv, ts);
+#endif
        return 0;
       }
 
diff --git a/sysdeps/mach/configure b/sysdeps/mach/configure
index 8aa6bbb1..311b2dd3 100644
--- a/sysdeps/mach/configure
+++ b/sysdeps/mach/configure
@@ -491,6 +491,36 @@ if test $libc_cv_mach_rpc_host_get_uptime64 = yes; then
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for host_get_time64 in 
mach_host.defs" >&5
+printf %s "checking for host_get_time64 in mach_host.defs... " >&6; }
+if test ${libc_cv_mach_rpc_host_get_time64+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <mach/mach_host.defs>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP_TRADITIONAL "host_get_time64" >/dev/null 2>&1
+then :
+  libc_cv_mach_rpc_host_get_time64=yes
+else case e in #(
+  e) libc_cv_mach_rpc_host_get_time64=no ;;
+esac
+fi
+rm -rf conftest*
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: 
$libc_cv_mach_rpc_host_get_time64" >&5
+printf "%s\n" "$libc_cv_mach_rpc_host_get_time64" >&6; }
+if test $libc_cv_mach_rpc_host_get_time64 = yes; then
+  printf "%s\n" "#define HAVE_HOST_GET_TIME64 1" >>confdefs.h
+
+fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for thread_set_name in 
gnumach.defs" >&5
 printf %s "checking for thread_set_name in gnumach.defs... " >&6; }
 if test ${libc_cv_mach_rpc_thread_set_name+y}
diff --git a/sysdeps/mach/configure.ac b/sysdeps/mach/configure.ac
index 08e5fdef..3a6f2443 100644
--- a/sysdeps/mach/configure.ac
+++ b/sysdeps/mach/configure.ac
@@ -94,6 +94,8 @@ mach_RPC_CHECK(mach_host.defs, host_page_size,
               HAVE_HOST_PAGE_SIZE)
 mach_RPC_CHECK(mach_host.defs, host_get_uptime64,
               HAVE_HOST_GET_UPTIME64)
+mach_RPC_CHECK(mach_host.defs, host_get_time64,
+              HAVE_HOST_GET_TIME64)
 mach_RPC_CHECK(gnumach.defs, thread_set_name,
               HAVE_MACH_THREAD_SET_NAME)
 mach_RPC_CHECK(gnumach.defs, thread_get_name,
-- 
2.47.2


Reply via email to