This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] Fix omp_get_wti{me,ck}


Hi!

Existing CLOCK_MONOTONIC define doesn't mean that clock_id is supported,
it may very well return -1/EINVAL.
CLOCK_REALTIME support is on the other side required:
http://www.opengroup.org/onlinepubs/009695399/functions/clock_getres.html
"All implementations shall support a clock_id of CLOCK_REALTIME as defined in
<time.h>."
so I think we don't need to fall back to gettimeofday or sysconf from that.
Fixes lib1.c and lib[123].f90 when running the testsuite on older Linux kernel.

Ok for gomp?

2005-11-28  Jakub Jelinek  <jakub@redhat.com>

	* config/posix/time.c (omp_get_wtime, omp_get_wtick): Fall back to
	CLOCK_REALTIME if clock_* (CLOCK_MONOTONIC, &ts) call failed.

--- libgomp/config/posix/time.c.jj	2005-11-25 10:01:30.000000000 +0100
+++ libgomp/config/posix/time.c	2005-11-28 14:37:17.000000000 +0100
@@ -51,10 +51,9 @@ omp_get_wtime (void)
 #ifdef HAVE_CLOCK_GETTIME
   struct timespec ts;
 # ifdef CLOCK_MONOTONIC
-  clock_gettime (CLOCK_MONOTONIC, &ts);
-# else
-  clock_gettime (CLOCK_REALTIME, &ts);
+  if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
 # endif
+    clock_gettime (CLOCK_REALTIME, &ts);
   return ts.tv_sec + ts.tv_nsec / 1e9;
 #else
   struct timeval tv;
@@ -69,10 +68,9 @@ omp_get_wtick (void)
 #ifdef HAVE_CLOCK_GETTIME
   struct timespec ts;
 # ifdef CLOCK_MONOTONIC
-  clock_getres (CLOCK_MONOTONIC, &ts);
-# else
-  clock_getres (CLOCK_REALTIME, &ts);
+  if (clock_getres (CLOCK_MONOTONIC, &ts) < 0)
 # endif
+    clock_getres (CLOCK_REALTIME, &ts);
   return ts.tv_sec + ts.tv_nsec / 1e9;
 #else
   return 1.0 / sysconf(_SC_CLK_TCK);

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]