[commit: ghc] master: Test return value of clock_gettime() for errors. (ee13437)

git at git.haskell.org git at git.haskell.org
Fri Apr 4 19:41:16 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ee1343712bb7854ef5b7180b1e600ac61be4ca13/ghc

>---------------------------------------------------------------

commit ee1343712bb7854ef5b7180b1e600ac61be4ca13
Author: Simon Marlow <marlowsd at gmail.com>
Date:   Tue Apr 1 13:10:27 2014 +0100

    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.


>---------------------------------------------------------------

ee1343712bb7854ef5b7180b1e600ac61be4ca13
 rts/posix/GetTime.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index bcee6ce..380e229 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
 }
 



More information about the ghc-commits mailing list