[commit: ghc] master: Use monotonic time function for darwin (#5865) (e57d23d)
Paolo Capriotti
p.capriotti at gmail.com
Tue Apr 17 20:04:18 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/e57d23d6f11c1262a096f2135e64a6a81d0ca938
>---------------------------------------------------------------
commit e57d23d6f11c1262a096f2135e64a6a81d0ca938
Author: Paolo Capriotti <p.capriotti at gmail.com>
Date: Sat Mar 24 02:19:43 2012 +0000
Use monotonic time function for darwin (#5865)
>---------------------------------------------------------------
rts/posix/Clock.h | 3 +++
rts/posix/GetTime.c | 11 +++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/rts/posix/Clock.h b/rts/posix/Clock.h
index 5062023..2c71d7a 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 4abc82f..549b3b0 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;
More information about the Cvs-ghc
mailing list