X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpoll-loop.c;h=de080b4c9e5d28c49fa4997fc92f5f1cf68f426a;hb=7593daa2473c464cd179420b9c7f68989044fdee;hp=5ff70d9ff5d9c73ccf7d3098cad81616cf1978d3;hpb=934264ec17192617f4acb1a4bb8a8e41d6b17b68;p=openvswitch diff --git a/lib/poll-loop.c b/lib/poll-loop.c index 5ff70d9f..de080b4c 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -62,6 +62,15 @@ static int timeout = -1; /* Location where waiter created. */ static const char *timeout_where; +/* Array of file descriptors from last run of poll_block(). */ +static struct pollfd *pollfds; + +/* Allocated size of pollfds. */ +static size_t max_pollfds; + +/* Current number of elements in pollfds. */ +static int n_pollfds; + static struct poll_waiter *new_waiter(int fd, short int events, const char *where); @@ -210,11 +219,8 @@ log_wakeup(const char *where, const struct pollfd *pollfd, int timeout) void poll_block(void) { - static struct pollfd *pollfds; - static size_t max_pollfds; - struct poll_waiter *pw, *next; - int n_waiters, n_pollfds; + int n_waiters; int retval; /* Register fatal signal events before actually doing any real work for @@ -275,6 +281,25 @@ poll_cancel(struct poll_waiter *pw) free(pw); } } + +/* Checks whether the given file descriptor caused the poll loop to wake up + * in the previous iteration. If it did, returns a bitmask of the events + * that caused the wakeup. Otherwise returns 0; + */ +short int +poll_fd_woke(int fd) +{ + int i; + short int events = 0; + + for (i = 0; i < n_pollfds; i++) { + if (pollfds[i].fd == fd) { + events |= pollfds[i].revents; + } + } + + return events; +} /* Creates and returns a new poll_waiter for 'fd' and 'events'. */ static struct poll_waiter *