diff options
author | Ben Pfaff <blp@nicira.com> | 2011-08-10 12:49:35 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-08-15 09:49:15 -0700 |
commit | 934264ec17192617f4acb1a4bb8a8e41d6b17b68 (patch) | |
tree | 83e2337608a58a8662dfb7f5f406371e7a86fb13 /lib/poll-loop.c | |
parent | 4ad2802695284467b559ca6790cd890359ffa159 (diff) |
poll-loop: Remove static variable n_waiters.
It's always a little risky to track the length of a list by hand, because
it is easy to miss a spot where the length can change. So it seems like
a small cleanup to just measure the length of the 'waiters' list at the
point where we need to know it. list_size() is O(n) in the length of the
list, but the function that calls it is already O(n) in that length so it
seems like a fair trade-off.
Diffstat (limited to 'lib/poll-loop.c')
-rw-r--r-- | lib/poll-loop.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/poll-loop.c b/lib/poll-loop.c index 9801d7de..5ff70d9f 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -55,9 +55,6 @@ struct poll_waiter { /* All active poll waiters. */ static struct list waiters = LIST_INITIALIZER(&waiters); -/* Number of elements in the waiters list. */ -static size_t n_waiters; - /* Max time to wait in next call to poll_block(), in milliseconds, or -1 to * wait forever. */ static int timeout = -1; @@ -217,13 +214,14 @@ poll_block(void) static size_t max_pollfds; struct poll_waiter *pw, *next; - int n_pollfds; + int n_waiters, n_pollfds; int retval; /* Register fatal signal events before actually doing any real work for * poll_block. */ fatal_signal_wait(); + n_waiters = list_size(&waiters); if (max_pollfds < n_waiters) { max_pollfds = n_waiters; pollfds = xrealloc(pollfds, max_pollfds * sizeof *pollfds); @@ -275,7 +273,6 @@ poll_cancel(struct poll_waiter *pw) if (pw) { list_remove(&pw->node); free(pw); - n_waiters--; } } @@ -289,6 +286,5 @@ new_waiter(int fd, short int events, const char *where) waiter->events = events; waiter->where = where; list_push_back(&waiters, &waiter->node); - n_waiters++; return waiter; } |