Commit 02b17751 by Janne Blomqvist

PR 47571 Fix HPUX bootstrap regression, cleanup

From-SVN: r169852
parent beea2755
2011-02-05 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/47571
* intrinsics/time_1.h (GF_CLOCK_MONOTONIC): Move to system_clock.c.
(weak_gettime): Likewise.
(gf_gettime): Change API, move weak_gettime() usage to
system_clock.c
* intrinsics/system_clock.c (GTHREAD_USE_WEAK): Define.
(gf_gettime_mono): New function.
(system_clock_4): Use gf_gettime_mono().
(system_clock_8): Likewise.
* intrinsics/date_and_time.c (date_and_time): Update gf_gettime()
usage.
2011-02-02 Janne Blomqvist <jb@gcc.gnu.org> 2011-02-02 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/47571 PR libfortran/47571
......
...@@ -162,11 +162,11 @@ date_and_time (char *__date, char *__time, char *__zone, ...@@ -162,11 +162,11 @@ date_and_time (char *__date, char *__time, char *__zone,
struct tm local_time; struct tm local_time;
struct tm UTC_time; struct tm UTC_time;
long nanosecs; long usecs;
if (!gf_gettime(GF_CLOCK_REALTIME, &lt, &nanosecs)) if (!gf_gettime (&lt, &usecs))
{ {
values[7] = nanosecs / 1000000; values[7] = usecs / 1000;
localtime_r (&lt, &local_time); localtime_r (&lt, &local_time);
gmtime_r (&lt, &UTC_time); gmtime_r (&lt, &UTC_time);
......
...@@ -29,6 +29,75 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see ...@@ -29,6 +29,75 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "time_1.h" #include "time_1.h"
#ifdef HAVE_CLOCK_GETTIME
/* POSIX states that CLOCK_REALTIME must be present if clock_gettime
is available, others are optional. */
#ifdef CLOCK_MONOTONIC
#define GF_CLOCK_MONOTONIC CLOCK_MONOTONIC
#else
#define GF_CLOCK_MONOTONIC CLOCK_REALTIME
#endif
/* Weakref trickery for clock_gettime(). On Glibc, clock_gettime()
requires us to link in librt, which also pulls in libpthread. In
order to avoid this by default, only call clock_gettime() through a
weak reference.
Some targets don't support weak undefined references; on these
GTHREAD_USE_WEAK is 0. So we need to define it to 1 on other
targets. */
#ifndef GTHREAD_USE_WEAK
#define GTHREAD_USE_WEAK 1
#endif
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
static int weak_gettime (clockid_t, struct timespec *)
__attribute__((__weakref__("clock_gettime")));
#else
static inline int weak_gettime (clockid_t clk_id, struct timespec *res)
{
return clock_gettime (clk_id, res);
}
#endif
#endif
/* High resolution monotonic clock, falling back to the realtime clock
if the target does not support such a clock.
Arguments:
secs - OUTPUT, seconds
nanosecs - OUTPUT, nanoseconds
If the target supports a monotonic clock, the OUTPUT arguments
represent a monotonically incrementing clock starting from some
unspecified time in the past.
If a monotonic clock is not available, falls back to the realtime
clock which is not monotonic.
Return value: 0 for success, -1 for error. In case of error, errno
is set.
*/
static inline int
gf_gettime_mono (time_t * secs, long * nanosecs)
{
int err;
#ifdef HAVE_CLOCK_GETTIME
if (weak_gettime)
{
struct timespec ts;
err = weak_gettime (GF_CLOCK_MONOTONIC, &ts);
*secs = ts.tv_sec;
*nanosecs = ts.tv_nsec;
return err;
}
#endif
err = gf_gettime (secs, nanosecs);
*nanosecs *= 1000;
return err;
}
extern void system_clock_4 (GFC_INTEGER_4 *, GFC_INTEGER_4 *, GFC_INTEGER_4 *); extern void system_clock_4 (GFC_INTEGER_4 *, GFC_INTEGER_4 *, GFC_INTEGER_4 *);
export_proto(system_clock_4); export_proto(system_clock_4);
...@@ -56,7 +125,7 @@ system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate, ...@@ -56,7 +125,7 @@ system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
if (sizeof (secs) < sizeof (GFC_INTEGER_4)) if (sizeof (secs) < sizeof (GFC_INTEGER_4))
internal_error (NULL, "secs too small"); internal_error (NULL, "secs too small");
if (gf_gettime (GF_CLOCK_MONOTONIC, &secs, &nanosecs) == 0) if (gf_gettime_mono (&secs, &nanosecs) == 0)
{ {
GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * TCK; GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * TCK;
ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK); ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK);
...@@ -103,7 +172,7 @@ system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate, ...@@ -103,7 +172,7 @@ system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
if (sizeof (secs) < sizeof (GFC_INTEGER_4)) if (sizeof (secs) < sizeof (GFC_INTEGER_4))
internal_error (NULL, "secs too small"); internal_error (NULL, "secs too small");
if (gf_gettime (GF_CLOCK_MONOTONIC, &secs, &nanosecs) == 0) if (gf_gettime_mono (&secs, &nanosecs) == 0)
{ {
GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * TCK; GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * TCK;
ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK); ucnt += (nanosecs + 500000000 / TCK) / (1000000000 / TCK);
......
...@@ -175,87 +175,40 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec ...@@ -175,87 +175,40 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec
#endif #endif
/* POSIX states that CLOCK_REALTIME must be present if clock_gettime /* Realtime clock with microsecond resolution, falling back to less
is available, others are optional. */ precise functions if the target does not support gettimeofday().
#ifdef CLOCK_REALTIME
#define GF_CLOCK_REALTIME CLOCK_REALTIME
#else
#define GF_CLOCK_REALTIME 0
#endif
#ifdef CLOCK_MONOTONIC
#define GF_CLOCK_MONOTONIC CLOCK_MONOTONIC
#else
#define GF_CLOCK_MONOTONIC GF_CLOCK_REALTIME
#endif
/* Weakref trickery for clock_gettime(). On Glibc, clock_gettime()
requires us to link in librt, which also pulls in libpthread. In
order to avoid this by default, only call clock_gettime() through a
weak reference. */
#ifdef HAVE_CLOCK_GETTIME
#ifdef SUPPORTS_WEAK
static int weak_gettime (clockid_t, struct timespec *)
__attribute__((__weakref__("clock_gettime")));
#else
static inline int weak_gettime (clockid_t clk_id, struct timespec *res)
{
return clock_gettime (clk_id, res);
}
#endif
#endif
/* Arguments: Arguments:
clock_id - INPUT, must be either GF_CLOCK_REALTIME or GF_CLOCK_MONOTONIC
secs - OUTPUT, seconds secs - OUTPUT, seconds
nanosecs - OUTPUT, OPTIONAL, nanoseconds usecs - OUTPUT, microseconds
If clock_id equals GF_CLOCK_REALTIME, the OUTPUT arguments shall be The OUTPUT arguments shall represent the number of seconds and
the number of seconds and nanoseconds since the Epoch. If clock_id nanoseconds since the Epoch.
equals GF_CLOCK_MONOTONIC, and if the target supports it, the
OUTPUT arguments represent a monotonically incrementing clock
starting from some unspecified time in the past.
Return value: 0 for success, -1 for error. In case of error, errno Return value: 0 for success, -1 for error. In case of error, errno
is set. is set.
*/ */
static inline int static inline int
gf_gettime (int clock_id __attribute__((unused)), time_t * secs, gf_gettime (time_t * secs, long * usecs)
long * nanosecs)
{ {
#ifdef HAVE_CLOCK_GETTIME
if (weak_gettime)
{
struct timespec ts;
int err;
err = weak_gettime (clock_id, &ts);
*secs = ts.tv_sec;
if (nanosecs)
*nanosecs = ts.tv_nsec;
return err;
}
#endif
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
struct timeval tv; struct timeval tv;
int err; int err;
err = gettimeofday (&tv, NULL); err = gettimeofday (&tv, NULL);
*secs = tv.tv_sec; *secs = tv.tv_sec;
if (nanosecs) *usecs = tv.tv_usec;
*nanosecs = tv.tv_usec * 1000;
return err; return err;
#elif HAVE_TIME #elif HAVE_TIME
time_t t, t2; time_t t, t2;
t = time (&t2); t = time (&t2);
*secs = t2; *secs = t2;
if (nanosecs) *usecs = 0;
*nanosecs = 0;
if (t == ((time_t)-1)) if (t == ((time_t)-1))
return -1; return -1;
return 0; return 0;
#else #else
*secs = 0; *secs = 0;
if (nanosecs) *usecs = 0;
*nanosecs = 0;
errno = ENOSYS; errno = ENOSYS;
return -1; return -1;
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment