diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-05-27 15:35:00 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-05-27 15:35:00 +0000 |
commit | cdaca02c2909452de23244738630f408b8eee8e1 (patch) | |
tree | 2480a96e21339e0a491279413dbec82a447b7bcd /poll.c | |
parent | 11a178f2bdd533d4f4cf7448653b0adc30c9779f (diff) | |
download | libevent-cdaca02c2909452de23244738630f408b8eee8e1.tar.gz |
Activate fd events in a pseudorandom order on older backends.
New backends like poll and kqueue and so on add fds to the queue in
the order that they are triggered. But the select backend currently
activates low-numbered fds first, whereas the poll and win32 backends
currently favor whatever fds have been on for the longest. This is no
good for fairness.
svn:r1318
Diffstat (limited to 'poll.c')
-rw-r--r-- | poll.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -117,7 +117,7 @@ poll_check_ok(struct pollop *pop) static int poll_dispatch(struct event_base *base, struct timeval *tv) { - int res, i, msec = -1, nfds; + int res, i, j, msec = -1, nfds; struct pollop *pop = base->evbase; poll_check_ok(pop); @@ -142,11 +142,15 @@ poll_dispatch(struct event_base *base, struct timeval *tv) event_debug(("%s: poll reports %d", __func__, res)); - if (res == 0) + if (res == 0 || nfds == 0) return (0); - for (i = 0; i < nfds; i++) { - int what = pop->event_set[i].revents; + i = random() % nfds; + for (j = 0; j < nfds; j++) { + int what; + if (++i == nfds) + i = 0; + what = pop->event_set[i].revents; if (!what) continue; |