From 5ba7db93fb634ff8094f42780a14972322446a94 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Tue, 20 Mar 2012 11:57:28 +0000 Subject: Use monotonic clock in Select.c (#5865) --- rts/posix/GetTime.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'rts/posix/GetTime.c') diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index 16511ce2e2..4abc82f6b9 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -11,23 +11,12 @@ #include "Rts.h" #include "GetTime.h" - -#ifdef HAVE_TIME_H -# include -#endif - -#ifdef HAVE_SYS_TIME_H -# include -#endif +#include "Clock.h" #if HAVE_SYS_RESOURCE_H # include #endif -#ifdef HAVE_UNISTD_H -# include -#endif - #ifdef HAVE_SYS_TIMES_H # include #endif @@ -77,9 +66,17 @@ Time getProcessCPUTime(void) Time getProcessElapsedTime(void) { +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + + clock_gettime(CLOCK_ID, &ts); + return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec); +#else struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); return SecondsToTime(tv.tv_sec) + USToTime(tv.tv_usec); +#endif } void getProcessTimes(Time *user, Time *elapsed) -- cgit v1.2.1