summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rts/posix/Clock.h3
-rw-r--r--rts/posix/GetTime.c11
2 files changed, 14 insertions, 0 deletions
diff --git a/rts/posix/Clock.h b/rts/posix/Clock.h
index 5062023fb6..2c71d7a75d 100644
--- a/rts/posix/Clock.h
+++ b/rts/posix/Clock.h
@@ -27,6 +27,9 @@
# else
# define CLOCK_ID CLOCK_REALTIME
# endif
+#elif defined(darwin_HOST_OS)
+# include <mach/mach.h>
+# include <mach/mach_time.h>
#endif
#endif /* POSIX_CLOCK_H */
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index 4abc82f6b9..549b3b0878 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -71,6 +71,17 @@ Time getProcessElapsedTime(void)
clock_gettime(CLOCK_ID, &ts);
return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec);
+#elif defined(darwin_HOST_OS)
+ uint64_t time = mach_absolute_time();
+ static double scaling_factor = 0.0;
+
+ if (scaling_factor == 0.0) {
+ mach_timebase_info_data_t info;
+ (void) mach_timebase_info(&info);
+ scaling_factor = (double)info.numer / (double)info.denom;
+ }
+
+ return (Time)((double)time * scaling_factor);
#else
struct timeval tv;