summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2012-05-26 11:41:12 +0100
committerIan Lynagh <igloo@earth.li>2012-05-26 11:47:21 +0100
commitd0d0c36a99c588f47d530eae0e505e5a9d317339 (patch)
tree76a1828e22d75128671464e7b7141f58a5be6579
parent05289c2ac1203a5d5bbe8236d0239946b5093116 (diff)
downloadhaskell-d0d0c36a99c588f47d530eae0e505e5a9d317339.tar.gz
Fix problems with getMonotonicNSec on OS X
We were incorrectly multiplying by 1e9, which (a) meant we were getting values that were far too large, and (b) meant that when we casted from double to StgWord64 the result was 0, as the value was out of range. We now do all the work as StgWord64.
-rw-r--r--rts/posix/GetTime.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index da8d0fa629..fabc40431d 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -34,7 +34,8 @@
// separately, using getrusage() and gettimeofday() respectively
#ifdef darwin_HOST_OS
-static double timer_scaling_factor_ns = 0.0;
+static uint64_t timer_scaling_factor_numer = 0;
+static uint64_t timer_scaling_factor_denom = 0;
#endif
void initializeTimer()
@@ -42,7 +43,8 @@ void initializeTimer()
#ifdef darwin_HOST_OS
mach_timebase_info_data_t info;
(void) mach_timebase_info(&info);
- timer_scaling_factor_ns = (double)info.numer / (double)info.denom * 1e9;
+ timer_scaling_factor_numer = (uint64_t)info.numer;
+ timer_scaling_factor_denom = (uint64_t)info.denom;
#endif
}
@@ -87,7 +89,7 @@ StgWord64 getMonotonicNSec(void)
(StgWord64)ts.tv_nsec;
#elif defined(darwin_HOST_OS)
uint64_t time = mach_absolute_time();
- return (double)time * timer_scaling_factor_ns;
+ return (time * timer_scaling_factor_numer) / timer_scaling_factor_denom;
#else
struct timeval tv;