diff options
author | Simon Marlow <marlowsd@gmail.com> | 2014-04-01 13:10:27 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2014-04-04 17:12:46 +0100 |
commit | ee1343712bb7854ef5b7180b1e600ac61be4ca13 (patch) | |
tree | a52d7dcf6939e671ca560c9ce6688d5f407d97d7 /rts/posix/GetTime.c | |
parent | 59b9b067b030d551f9b42423b50770c661c9d86c (diff) | |
download | haskell-ee1343712bb7854ef5b7180b1e600ac61be4ca13.tar.gz |
Test return value of clock_gettime() for errors.
I don't want to fall back to gettimeofday(), because that might have a
different absolute value.
Diffstat (limited to 'rts/posix/GetTime.c')
-rw-r--r-- | rts/posix/GetTime.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index bcee6ce127..380e22931b 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -81,21 +81,31 @@ Time getProcessCPUTime(void) StgWord64 getMonotonicNSec(void) { -#ifdef HAVE_CLOCK_GETTIME +#if defined(HAVE_CLOCK_GETTIME) struct timespec ts; + int res; - clock_gettime(CLOCK_ID, &ts); + res = clock_gettime(CLOCK_ID, &ts); + if (res != 0) { + sysErrorBelch("clock_gettime"); + stg_exit(EXIT_FAILURE); + } return (StgWord64)ts.tv_sec * 1000000000 + (StgWord64)ts.tv_nsec; + #elif defined(darwin_HOST_OS) + uint64_t time = mach_absolute_time(); return (time * timer_scaling_factor_numer) / timer_scaling_factor_denom; -#else + +#else // use gettimeofday() + struct timeval tv; gettimeofday(&tv, (struct timezone *) NULL); return (StgWord64)tv.tv_sec * 1000000000 + (StgWord64)tv.tv_usec * 1000; + #endif } |