X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Fpoll.c;h=36af33ef0854de3323c8f29c4dc522c976091764;hp=b1a28fdb3f6dbb866b449ac77ddd00cae46d8463;hb=8cb4a3ed3d44fa4f85e176aaeaaf1da1d6eab5b6;hpb=36bfb66bdf74f4f3382cd00dae7b899e80e2cf1a diff --git a/ccan/io/poll.c b/ccan/io/poll.c index b1a28fdb..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) { @@ -254,9 +262,9 @@ void *io_loop(struct timers *timers, struct timer **expired) assert(num_waiting); if (timers) { - struct timeabs now, first; + struct timemono now, first; - now = time_now(); + now = nowfn(); /* Call functions for expired timers. */ *expired = timers_expire(timers, now); @@ -266,7 +274,7 @@ void *io_loop(struct timers *timers, struct timer **expired) /* 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