X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpoll-loop.c;h=e47cccc392763f53c3e68ecfd987ca8894e99d1b;hb=cb034511802ff7516ca2a94da1e161965fb80ad0;hp=29931f7855ae53f0d4e2651443a6dba9b382ab01;hpb=8bf4bbe390af3f370e7e95d9237572ff750047a8;p=openvswitch diff --git a/lib/poll-loop.c b/lib/poll-loop.c index 29931f78..e47cccc3 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -28,10 +28,13 @@ #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); + +COVERAGE_DEFINE(poll_fd_wait); +COVERAGE_DEFINE(poll_zero_timeout); + /* An event that will wake the following call to poll_block(). */ struct poll_waiter { /* Set when the waiter is created. */ @@ -100,6 +103,23 @@ poll_timer_wait(long long int msec) : 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 * blocking. */ void @@ -154,7 +174,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; @@ -173,7 +193,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]" : "",