diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-03-24 02:19:43 +0000 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-16 15:18:19 +0100 |
commit | e57d23d6f11c1262a096f2135e64a6a81d0ca938 (patch) | |
tree | 45a53254b66b41eac22036805ef66afa047f31cb /rts/posix/GetTime.c | |
parent | 5ba7db93fb634ff8094f42780a14972322446a94 (diff) | |
download | haskell-e57d23d6f11c1262a096f2135e64a6a81d0ca938.tar.gz |
Use monotonic time function for darwin (#5865)
Diffstat (limited to 'rts/posix/GetTime.c')
-rw-r--r-- | rts/posix/GetTime.c | 11 |
1 files changed, 11 insertions, 0 deletions
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; |