From 2d3c2db8683eac3572a5c21fcbb08d656e66f1ea Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 29 Jan 2018 15:56:24 +0100 Subject: [PATCH] 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. --- src/ev_poll.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ev_poll.c b/src/ev_poll.c index 2e67a9dc3..2460a6713 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); } }