Handle clock_gettime failing
authorIan Lynagh <igloo@earth.li>
Wed, 27 Sep 2006 23:46:30 +0000 (23:46 +0000)
committerIan Lynagh <igloo@earth.li>
Wed, 27 Sep 2006 23:46:30 +0000 (23:46 +0000)
rts/posix/GetTime.c

index 0e591ef..a2d9a31 100644 (file)
@@ -44,7 +44,7 @@ Ticks getProcessCPUTime(void)
 {
     struct rusage t;
     getrusage(RUSAGE_SELF, &t);
-    return ((Ticks)t.ru_utime.tv_sec * TICKS_PER_SECOND + 
+    return ((Ticks)t.ru_utime.tv_sec * TICKS_PER_SECOND +
            ((Ticks)t.ru_utime.tv_usec * TICKS_PER_SECOND)/1000000);
 }
 
@@ -119,12 +119,14 @@ Ticks getThreadCPUTime(void)
     // clock_gettime() gives us per-thread CPU time.  It isn't
     // reliable on Linux, but it's the best we have.
     struct timespec ts;
-    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
-    return ((Ticks)ts.tv_sec * TICKS_PER_SECOND + 
-           ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
-#else
-    return getProcessCPUTime();
+    int res;
+    res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
+    if (res == 0) {
+        return ((Ticks)ts.tv_sec * TICKS_PER_SECOND +
+                ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
+    }
 #endif
+    return getProcessCPUTime();
 }
 
 nat