diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-02-02 10:48:24 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-02-02 10:48:24 +0200 |
commit | aa8374708a2e5e47266b7e65f710506d237a38db (patch) | |
tree | 74e43d0af93ad7827a8164bfa3ba1469d9f6c579 /libgfortran/intrinsics | |
parent | e829c3213bab0c0126336b4ffdd60605874e3783 (diff) | |
download | gcc-aa8374708a2e5e47266b7e65f710506d237a38db.zip gcc-aa8374708a2e5e47266b7e65f710506d237a38db.tar.gz gcc-aa8374708a2e5e47266b7e65f710506d237a38db.tar.bz2 |
PR 47571 Weakref trickery for clock_gettime()
From-SVN: r169517
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r-- | libgfortran/intrinsics/time_1.h | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/libgfortran/intrinsics/time_1.h b/libgfortran/intrinsics/time_1.h index 58c51af..86e4331 100644 --- a/libgfortran/intrinsics/time_1.h +++ b/libgfortran/intrinsics/time_1.h @@ -189,6 +189,22 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec #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: clock_id - INPUT, must be either GF_CLOCK_REALTIME or GF_CLOCK_MONOTONIC secs - OUTPUT, seconds @@ -208,14 +224,18 @@ gf_gettime (int clock_id __attribute__((unused)), time_t * secs, long * nanosecs) { #ifdef HAVE_CLOCK_GETTIME - struct timespec ts; - int err; - err = clock_gettime (clock_id, &ts); - *secs = ts.tv_sec; - if (nanosecs) - *nanosecs = ts.tv_nsec; - return err; -#elif HAVE_GETTIMEOFDAY + 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 struct timeval tv; int err; err = gettimeofday (&tv, NULL); |