X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fpoll-loop.c;h=6aefc7689b11cf36741ff444aaf2ea73c9463264;hb=c424adb3ac3460818256181a073b09e92cdc562a;hp=8f65f9402ae94bcd3d595e7d81d2513a30cbe9d7;hpb=02dd3123a0e312f1d33403e744af52dd6096f12d;p=sliver-openvswitch.git diff --git a/lib/poll-loop.c b/lib/poll-loop.c index 8f65f9402..6aefc7689 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -28,10 +28,10 @@ #include "fatal-signal.h" #include "list.h" #include "timeval.h" - -#define THIS_MODULE VLM_poll_loop #include "vlog.h" +VLOG_DEFINE_THIS_MODULE(poll_loop) + /* An event that will wake the following call to poll_block(). */ struct poll_waiter { /* Set when the waiter is created. */ @@ -73,6 +73,18 @@ poll_fd_wait(int fd, short int events) return new_waiter(fd, events); } +/* The caller must ensure that 'msec' is not negative. */ +static void +poll_timer_wait__(int msec) +{ + if (timeout < 0 || msec < timeout) { + timeout = msec; + if (VLOG_IS_DBG_ENABLED()) { + backtrace_capture(&timeout_backtrace); + } + } +} + /* Causes the following call to poll_block() to block for no more than 'msec' * milliseconds. If 'msec' is nonpositive, the following call to poll_block() * will not block at all. @@ -81,14 +93,28 @@ poll_fd_wait(int fd, short int events) * is affected. The timer will need to be re-registered after poll_block() is * called if it is to persist. */ void -poll_timer_wait(int msec) +poll_timer_wait(long long int msec) { - if (timeout < 0 || msec < timeout) { - timeout = MAX(0, msec); - if (VLOG_IS_DBG_ENABLED()) { - backtrace_capture(&timeout_backtrace); - } - } + poll_timer_wait__(msec < 0 ? 0 + : msec > INT_MAX ? INT_MAX + : msec); +} + +/* Causes the following call to poll_block() to wake up when the current time, + * as returned by time_msec(), reaches 'msec' or later. If 'msec' is earlier + * than the current time, the following call to poll_block() will not block at + * all. + * + * The timer registration is one-shot: only the following call to poll_block() + * is affected. The timer will need to be re-registered after poll_block() is + * called if it is to persist. */ +void +poll_timer_wait_until(long long int msec) +{ + long long int now = time_msec(); + poll_timer_wait__(msec <= now ? 0 + : msec < now + INT_MAX ? msec - now + : INT_MAX); } /* Causes the following call to poll_block() to wake up immediately, without @@ -145,7 +171,7 @@ poll_block(void) } n_pollfds = 0; - LIST_FOR_EACH (pw, struct poll_waiter, node, &waiters) { + LIST_FOR_EACH (pw, node, &waiters) { pw->pollfd = &pollfds[n_pollfds]; pollfds[n_pollfds].fd = pw->fd; pollfds[n_pollfds].events = pw->events; @@ -164,7 +190,7 @@ poll_block(void) log_wakeup(&timeout_backtrace, "%d-ms timeout", timeout); } - LIST_FOR_EACH_SAFE (pw, next, struct poll_waiter, node, &waiters) { + LIST_FOR_EACH_SAFE (pw, next, node, &waiters) { if (pw->pollfd->revents && VLOG_IS_DBG_ENABLED()) { log_wakeup(pw->backtrace, "%s%s%s%s%s on fd %d", pw->pollfd->revents & POLLIN ? "[POLLIN]" : "",