aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/mach/clock_gettime.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach/clock_gettime.c')
-rw-r--r--sysdeps/mach/clock_gettime.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sysdeps/mach/clock_gettime.c b/sysdeps/mach/clock_gettime.c
index 1392475963..d8c6681ec5 100644
--- a/sysdeps/mach/clock_gettime.c
+++ b/sysdeps/mach/clock_gettime.c
@@ -20,6 +20,7 @@
#include <mach.h>
#include <assert.h>
#include <shlib-compat.h>
+#include <mach/mig_errors.h>
/* Get the current time of day, putting it into *TS.
Returns 0 on success, -1 on errors. */
@@ -31,6 +32,29 @@ __clock_gettime (clockid_t clock_id, struct timespec *ts)
switch (clock_id) {
+ case CLOCK_MONOTONIC:
+ /* If HAVE_HOST_GET_UPTIME64 is not defined or not available,
+ CLOCK_MONOTONIC will be equivalent to CLOCK_REALTIME. */
+#ifdef HAVE_HOST_GET_UPTIME64
+ {
+ time_value64_t tv;
+ err = __host_get_uptime64 (__mach_host_self (), &tv);
+
+ if (err != MIG_BAD_ID)
+ {
+ if (err)
+ {
+ __set_errno (err);
+ return -1;
+ }
+
+ TIME_VALUE64_TO_TIMESPEC (&tv, ts);
+ return 0;
+ }
+ }
+ /* FALLTHROUGH */
+#endif
+
case CLOCK_REALTIME:
{
/* __host_get_time can only fail if passed an invalid host_t.