On 1/1/25 5:51 PM, Zhaoming Luo wrote:
---
  sysdeps/mach/clock_gettime.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
The website[0] mentions making `gettimeofday()` use the CLOCK_MONOTONIC. Does that refer to this one[1]?

[0]: https://darnassus.sceen.net/~hurd-web/open_issues/clock_gettime/
[1]: https://sourceware.org/git?p=glibc.git;a=blob;f=time/gettimeofday.c;h=bf92756cae906b9afff44d302800babbb1413b4a;hb=HEAD#l26

diff --git a/sysdeps/mach/clock_gettime.c b/sysdeps/mach/clock_gettime.c
index 6fffad39f5..22faf85730 100644
--- a/sysdeps/mach/clock_gettime.c
+++ b/sysdeps/mach/clock_gettime.c
@@ -31,6 +31,18 @@ __clock_gettime (clockid_t clock_id, struct timespec *ts)
switch (clock_id) { + case CLOCK_MONOTONIC:
+      {
+       /* __host_get_uptime64 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.  */
+       time_value64_t tv;
+       __host_get_uptime64 (__mach_host_self (), &tv);
+       TIME_VALUE64_TO_TIMESPEC (&tv, ts);
+       return 0;
+      }
+
      case CLOCK_REALTIME:
        {
        /* __host_get_time can only fail if passed an invalid host_t.

--
Zhaoming Luo


Reply via email to