From 72aedc1e80c7370e3413300c5d2ec04ac1713e0b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Oct 2013 05:57:05 +0200 Subject: event: properly disarm timers when we don't need them anymore --- src/libsystemd-bus/sd-event.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/libsystemd-bus') diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c index 3599d90eb4..dd8d3ee629 100644 --- a/src/libsystemd-bus/sd-event.c +++ b/src/libsystemd-bus/sd-event.c @@ -1384,8 +1384,20 @@ static int event_arm_timer( assert_se(next); a = prioq_peek(earliest); - if (!a || a->enabled == SD_EVENT_OFF) + if (!a || a->enabled == SD_EVENT_OFF) { + + if (*next == (usec_t) -1) + return 0; + + /* disarm */ + r = timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &its, NULL); + if (r < 0) + return r; + + *next = (usec_t) -1; + return 0; + } b = prioq_peek(latest); assert_se(b && b->enabled != SD_EVENT_OFF); @@ -1430,12 +1442,14 @@ static int process_io(sd_event *e, sd_event_source *s, uint32_t events) { return source_set_pending(s, true); } -static int flush_timer(sd_event *e, int fd, uint32_t events) { +static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) { uint64_t x; ssize_t ss; assert(e); assert(fd >= 0); + assert(next); + assert_return(events == EPOLLIN, -EIO); ss = read(fd, &x, sizeof(x)); @@ -1449,6 +1463,8 @@ static int flush_timer(sd_event *e, int fd, uint32_t events) { if (ss != sizeof(x)) return -EIO; + *next = (usec_t) -1; + return 0; } @@ -1741,9 +1757,9 @@ int sd_event_run(sd_event *e, uint64_t timeout) { for (i = 0; i < m; i++) { if (ev_queue[i].data.ptr == INT_TO_PTR(SOURCE_MONOTONIC)) - r = flush_timer(e, e->monotonic_fd, ev_queue[i].events); + r = flush_timer(e, e->monotonic_fd, ev_queue[i].events, &e->monotonic_next); else if (ev_queue[i].data.ptr == INT_TO_PTR(SOURCE_REALTIME)) - r = flush_timer(e, e->realtime_fd, ev_queue[i].events); + r = flush_timer(e, e->realtime_fd, ev_queue[i].events, &e->realtime_next); else if (ev_queue[i].data.ptr == INT_TO_PTR(SOURCE_SIGNAL)) r = process_signal(e, ev_queue[i].events); else -- cgit v1.2.3-54-g00ecf