summaryrefslogtreecommitdiff
path: root/rts/posix/GetTime.c
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2007-01-16 01:29:07 +0000
committerIan Lynagh <igloo@earth.li>2007-01-16 01:29:07 +0000
commita89ac49312ff740591226f0a6fd9322f15289c62 (patch)
treef6cf9d43e31759cd68fec5848651e2f9ef0ee571 /rts/posix/GetTime.c
parent50ebea6a8607f4d83dd2d8d99acf9a55e4d39349 (diff)
downloadhaskell-a89ac49312ff740591226f0a6fd9322f15289c62.tar.gz
Check with sysconf _POSIX_THREAD_CPUTIME is available before we try to use it.
Calling clock_gettime(CLOCK_THREAD_CPUTIME_ID,_) regardless was causing a segfault (trac #1030).
Diffstat (limited to 'rts/posix/GetTime.c')
-rw-r--r--rts/posix/GetTime.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index db7378d62b..626882b205 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -134,15 +134,17 @@ Ticks getThreadCPUTime(void)
}
return ((usec * TICKS_PER_SECOND) / 1000000);
-#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID)
- // clock_gettime() gives us per-thread CPU time. It isn't
- // reliable on Linux, but it's the best we have.
- struct timespec ts;
- 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);
+#elif defined(HAVE_CLOCK_GETTIME) && defined (_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
+ if (sysconf(_POSIX_THREAD_CPUTIME) != -1) {
+ // clock_gettime() gives us per-thread CPU time. It isn't
+ // reliable on Linux, but it's the best we have.
+ struct timespec ts;
+ 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();