X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Fpoll.c;h=36af33ef0854de3323c8f29c4dc522c976091764;hb=4bb69fe6d568f84bd682cf6f86bae168313deb91;hp=3266bdb2f5c737baecde62870445f90597895cfe;hpb=f3c92802bfdb388f8c191cd1c682f90bc485b357;p=ccan diff --git a/ccan/io/poll.c b/ccan/io/poll.c index 3266bdb2..36af33ef 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -16,6 +16,14 @@ static struct pollfd *pollfds = NULL; static struct fd **fds = NULL; static LIST_HEAD(closing); static LIST_HEAD(always); +static struct timemono (*nowfn)(void) = time_mono; + +struct timemono (*io_time_override(struct timemono (*now)(void)))(void) +{ + struct timemono (*old)(void) = nowfn; + nowfn = now; + return old; +} static bool add_fd(struct fd *fd, short events) { @@ -222,16 +230,16 @@ static bool handle_always(void) } /* This is the main loop. */ -void *io_loop(struct timers *timers, struct list_head *expired) +void *io_loop(struct timers *timers, struct timer **expired) { void *ret; /* if timers is NULL, expired must be. If not, not. */ assert(!timers == !expired); - /* Make sure this is empty if we exit for some other reason. */ + /* Make sure this is NULL if we exit for some other reason. */ if (expired) - list_head_init(expired); + *expired = NULL; while (!io_loop_return) { int i, r, ms_timeout = -1; @@ -254,19 +262,19 @@ void *io_loop(struct timers *timers, struct list_head *expired) assert(num_waiting); if (timers) { - struct timeabs now, first; + struct timemono now, first; - now = time_now(); + now = nowfn(); /* Call functions for expired timers. */ - timers_expire(timers, now, expired); - if (!list_empty(expired)) + *expired = timers_expire(timers, now); + if (*expired) break; /* Now figure out how long to wait for the next one. */ if (timer_earliest(timers, &first)) { uint64_t next; - next = time_to_msec(time_between(first, now)); + next = time_to_msec(timemono_between(first, now)); if (next < INT_MAX) ms_timeout = next; else