From: Willy Tarreau Date: Mon, 29 Jan 2018 14:56:24 +0000 (+0100) Subject: MINOR: poll: more accurately compute the new maxfd in the loop X-Git-Tag: v1.9-dev1~477 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d3c2db8683eac3572a5c21fcbb08d656e66f1ea;p=thirdparty%2Fhaproxy.git MINOR: poll: more accurately compute the new maxfd in the loop Last commit 173d995 ("MEDIUM: polling: start to move maxfd computation to the pollers") moved the maxfd computation to the polling loop, but it still adds an entry when removing an fd, forcing the next loop to seek from further away than necessary. Let's only update the max when actually adding an entry. --- diff --git a/src/ev_poll.c b/src/ev_poll.c index 2e67a9dc3f..2460a67132 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -96,17 +96,21 @@ REGPRM2 static void _do_poll(struct poller *p, int exp) HA_SPIN_LOCK(POLL_LOCK, &poll_lock); if ((eo & ~en) & FD_EV_POLLED_R) hap_fd_clr(fd, fd_evts[DIR_RD]); - else if ((en & ~eo) & FD_EV_POLLED_R) + else if ((en & ~eo) & FD_EV_POLLED_R) { hap_fd_set(fd, fd_evts[DIR_RD]); + if (fd > max_add_fd) + max_add_fd = fd; + } if ((eo & ~en) & FD_EV_POLLED_W) hap_fd_clr(fd, fd_evts[DIR_WR]); - else if ((en & ~eo) & FD_EV_POLLED_W) + else if ((en & ~eo) & FD_EV_POLLED_W) { hap_fd_set(fd, fd_evts[DIR_WR]); - HA_SPIN_UNLOCK(POLL_LOCK, &poll_lock); + if (fd > max_add_fd) + max_add_fd = fd; + } - if (fd > max_add_fd) - max_add_fd = fd; + HA_SPIN_UNLOCK(POLL_LOCK, &poll_lock); } }