This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp] Fix omp_get_wti{me,ck}
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 28 Nov 2005 11:13:36 -0500
- Subject: [gomp] Fix omp_get_wti{me,ck}
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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