From 024ad276aadd08e5be967a50a31cde9ee8626efa Mon Sep 17 00:00:00 2001 From: root Date: Fri, 6 Feb 2009 20:17:43 +0000 Subject: *** empty log message *** --- Changes | 8 +++++++- ev.c | 45 ++++++++++++++++++++++++++++++++------------- ev.pod | 12 +++++++----- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Changes b/Changes index 08eec5a..e6c0ed1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for libev, a high-performance and full-featured event loop. + - probe for CLOCK_REALTIME support at runtime as well and fall + back to gettimeofday if there is an error, to support older + operating systems with newer header files/libraries. + - prefer gettimeofday over clock_gettime with USE_CLOCK_SYSCALL + (default most everywhere), otherwise not. + 3.52 Wed Jan 7 21:43:02 CET 2009 - fix compilation of select backend in fd_set mode when NFDBITS is missing (to get it to compile on QNX, reported by Rodrigo Campos). @@ -13,7 +19,7 @@ Revision history for libev, a high-performance and full-featured event loop. attacks harder (but not impossible - it's windows). Make sure it even works under vista, which thinks that getpeer/sockname should return fantasy port numbers. - - include "libev" all assertion messages for potentially + - include "libev" in all assertion messages for potentially clearer diagnostics. - event_get_version (libevent compatibility) returned a useless string instead of the expected version string diff --git a/ev.c b/ev.c index 0d8ca4e..7b8a92c 100644 --- a/ev.c +++ b/ev.c @@ -66,7 +66,7 @@ extern "C" { # define EV_USE_MONOTONIC 1 # endif # ifndef EV_USE_REALTIME -# define EV_USE_REALTIME 1 +# define EV_USE_REALTIME 0 # endif # else # ifndef EV_USE_MONOTONIC @@ -195,7 +195,7 @@ extern "C" { #endif #ifndef EV_USE_REALTIME -# define EV_USE_REALTIME 0 +# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL #endif #ifndef EV_USE_NANOSLEEP @@ -399,9 +399,13 @@ typedef ev_watcher_time *WT; #define ev_active(w) ((W)(w))->active #define ev_at(w) ((WT)(w))->at -#if EV_USE_MONOTONIC +#if EV_USE_REALTIME /* sig_atomic_t is used to avoid per-thread variables or locking but still */ /* giving it a reasonably high chance of working on typical architetcures */ +static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ +#endif + +#if EV_USE_MONOTONIC static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ #endif @@ -555,14 +559,17 @@ ev_tstamp ev_time (void) { #if EV_USE_REALTIME - struct timespec ts; - clock_gettime (CLOCK_REALTIME, &ts); - return ts.tv_sec + ts.tv_nsec * 1e-9; -#else + if (expect_true (have_realtime)) + { + struct timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + return ts.tv_sec + ts.tv_nsec * 1e-9; + } +#endif + struct timeval tv; gettimeofday (&tv, 0); return tv.tv_sec + tv.tv_usec * 1e-6; -#endif } ev_tstamp inline_size @@ -1321,12 +1328,24 @@ loop_init (EV_P_ unsigned int flags) { if (!backend) { +#if EV_USE_REALTIME + if (!have_realtime) + { + struct timespec ts; + + if (!clock_gettime (CLOCK_REALTIME, &ts)) + have_realtime = 1; + } +#endif + #if EV_USE_MONOTONIC - { - struct timespec ts; - if (!clock_gettime (CLOCK_MONOTONIC, &ts)) - have_monotonic = 1; - } + if (!have_monotonic) + { + struct timespec ts; + + if (!clock_gettime (CLOCK_MONOTONIC, &ts)) + have_monotonic = 1; + } #endif ev_rt_now = ev_time (); diff --git a/ev.pod b/ev.pod index f9de137..15b1965 100644 --- a/ev.pod +++ b/ev.pod @@ -3231,11 +3231,13 @@ function is hiding in (often F<-lrt>). See also C. =item EV_USE_REALTIME If defined to be C<1>, libev will try to detect the availability of the -real-time clock option at compile time (and assume its availability at -runtime if successful). Otherwise no use of the real-time clock option will -be attempted. This effectively replaces C by C and will not normally affect correctness. See the -note about libraries in the description of C, though. +real-time clock option at compile time (and assume its availability +at runtime if successful). Otherwise no use of the real-time clock +option will be attempted. This effectively replaces C +by C and will not normally affect +correctness. See the note about libraries in the description of +C, though. Defaults to the opposite value of +C. =item EV_USE_CLOCK_SYSCALL -- cgit v1.2.3