diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-05-01 19:12:48 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-05-01 19:12:48 +0000 |
commit | 3cdb0eea499dad241387c906e072409d0186e2e5 (patch) | |
tree | 8a02d09180718900fa73129f39f52044d4891984 /lib | |
parent | 8e302c9be22576aa8a14a98ecc7f92ff38600b1c (diff) |
Require clock_gettime(CLOCK_MONOTONIC) and remove fallback code
If clock_gettime(CLOCK_MONOTONIC) fails here, something is really wrong.
Lots of userland already require it anyway. Removing the fallback code
means less code, less global state and less fiddling with the timeheap
internals.
ok nicm@ tedu@ tobias@ cheloha@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libevent/event.c | 74 |
1 files changed, 8 insertions, 66 deletions
diff --git a/lib/libevent/event.c b/lib/libevent/event.c index 48b7bcfbd43..97f9afe6aa4 100644 --- a/lib/libevent/event.c +++ b/lib/libevent/event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: event.c,v 1.39 2019/04/29 17:11:51 tobias Exp $ */ +/* $OpenBSD: event.c,v 1.40 2019/05/01 19:12:47 jca Exp $ */ /* * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> @@ -62,7 +62,6 @@ static const struct eventop *eventops[] = { /* Global state */ struct event_base *current_base = NULL; extern struct event_base *evsignal_base; -static int use_monotonic; /* Handle signals - This is a deprecated interface */ int (*event_sigcb)(void); /* Signal callback when gotsig is set */ @@ -77,37 +76,24 @@ static void event_process_active(struct event_base *); static int timeout_next(struct event_base *, struct timeval **); static void timeout_process(struct event_base *); -static void timeout_correct(struct event_base *, struct timeval *); - -static void -detect_monotonic(void) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) - use_monotonic = 1; -} static int gettime(struct event_base *base, struct timeval *tp) { + struct timespec ts; + if (base->tv_cache.tv_sec) { *tp = base->tv_cache; return (0); } - if (use_monotonic) { - struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) + event_err(1, "%s: clock_gettime", __func__); - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) - return (-1); - - tp->tv_sec = ts.tv_sec; - tp->tv_usec = ts.tv_nsec / 1000; - return (0); - } + tp->tv_sec = ts.tv_sec; + tp->tv_usec = ts.tv_nsec / 1000; - return (gettimeofday(tp, NULL)); + return (0); } struct event_base * @@ -133,7 +119,6 @@ event_base_new(void) event_sigcb = NULL; event_gotsig = 0; - detect_monotonic(); gettime(base, &base->event_tv); min_heap_ctor(&base->timeheap); @@ -466,8 +451,6 @@ event_base_loop(struct event_base *base, int flags) } } - timeout_correct(base, &tv); - tv_p = &tv; if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) { timeout_next(base, &tv_p); @@ -837,47 +820,6 @@ timeout_next(struct event_base *base, struct timeval **tv_p) return (0); } -/* - * Determines if the time is running backwards by comparing the current - * time against the last time we checked. Not needed when using clock - * monotonic. - */ - -static void -timeout_correct(struct event_base *base, struct timeval *tv) -{ - struct event **pev; - size_t size; - struct timeval off; - - if (use_monotonic) - return; - - /* Check if time is running backwards */ - gettime(base, tv); - if (timercmp(tv, &base->event_tv, >=)) { - base->event_tv = *tv; - return; - } - - event_debug(("%s: time is running backwards, corrected", - __func__)); - timersub(&base->event_tv, tv, &off); - - /* - * We can modify the key element of the node without destroying - * the key, beause we apply it to all in the right order. - */ - pev = base->timeheap.p; - size = base->timeheap.n; - for (; size-- > 0; ++pev) { - struct timeval *ev_tv = &(**pev).ev_timeout; - timersub(ev_tv, &off, ev_tv); - } - /* Now remember what the new time turned out to be. */ - base->event_tv = *tv; -} - void timeout_process(struct event_base *base) { |