diff options
author | Denis Vlasenko | 2007-08-31 21:45:52 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-08-31 21:45:52 +0000 |
commit | 7bc5360bba5ae057771200e2d5ae55c45f178c0d (patch) | |
tree | 0929ad64b228119c8f0bc7bda08fe5bb4c7f5907 | |
parent | 05241802a7c7c4f85b69f34c5c13df88cdf9fb1e (diff) | |
download | busybox-7bc5360bba5ae057771200e2d5ae55c45f178c0d.zip busybox-7bc5360bba5ae057771200e2d5ae55c45f178c0d.tar.gz |
isrv: use monotonic_sec
runsv: do not use clock_gettime if !MONOTONIC_CLOCK
-rw-r--r-- | networking/isrv.c | 18 | ||||
-rw-r--r-- | runit/runsv.c | 36 |
2 files changed, 30 insertions, 24 deletions
diff --git a/networking/isrv.c b/networking/isrv.c index 1a41dd4..080c60f 100644 --- a/networking/isrv.c +++ b/networking/isrv.c @@ -21,20 +21,6 @@ /* Helpers */ -/* Even if _POSIX_MONOTONIC_CLOCK is defined, this - * may require librt */ -#if 0 /*def _POSIX_MONOTONIC_CLOCK*/ -static time_t monotonic_time(void) -{ - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - time(&ts.tv_sec); - return ts.tv_sec; -} -#else -#define monotonic_time() (time(NULL)) -#endif - /* Opaque structure */ struct isrv_state_t { @@ -258,7 +244,7 @@ static void handle_fd_set(isrv_state_t *state, fd_set *fds, int (*h)(int, void * /* this peer is gone */ remove_peer(state, peer); } else if (TIMEOUT) { - TIMEO_TBL[peer] = monotonic_time(); + TIMEO_TBL[peer] = monotonic_sec(); } } } @@ -335,7 +321,7 @@ void isrv_run( break; if (timeout) { - time_t t = monotonic_time(); + time_t t = monotonic_sec(); if (t != CURTIME) { CURTIME = t; handle_timeout(state, do_timeout); diff --git a/runit/runsv.c b/runit/runsv.c index baef6e1..b35c266 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -33,6 +33,34 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "libbb.h" #include "runit_lib.h" +#if ENABLE_MONOTONIC_SYSCALL +#include <sys/syscall.h> + +/* libc has incredibly messy way of doing this, + * typically requiring -lrt. We just skip all this mess */ +static void gettimeofday_ns(struct timespec *ts) +{ + syscall(__NR_clock_gettime, CLOCK_REALTIME, ts); +} +#else +static void gettimeofday_ns(struct timespec *ts) +{ + if (sizeof(struct timeval) == sizeof(struct timespec) + && sizeof(((struct timeval*)ts)->tv_usec) == sizeof(ts->tv_nsec) + ) { + /* Cheat */ + gettimeofday((void*)ts, NULL); + ts->tv_nsec *= 1000; + } else { + extern void BUG_need_to_implement_gettimeofday_ns(void); + BUG_need_to_implement_gettimeofday_ns(); + } +} +#endif + +/* Compare possibly overflowing unsigned counters */ +#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) + static int selfpipe[2]; /* state */ @@ -126,14 +154,6 @@ static int rename_or_warn(const char *old, const char *new) return 0; } -#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) - -#include <sys/syscall.h> -static void gettimeofday_ns(struct timespec *ts) -{ - syscall(__NR_clock_gettime, CLOCK_REALTIME, ts); -} - static void update_status(struct svdir *s) { ssize_t sz; |