]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: poll: more accurately compute the new maxfd in the loop
authorWilly Tarreau <w@1wt.eu>
Mon, 29 Jan 2018 14:56:24 +0000 (15:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 29 Jan 2018 15:00:28 +0000 (16:00 +0100)
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

index 2e67a9dc3fb6262596c55a0c2f6cb87467bcedfc..2460a67132e1288178fcfacdc4b4899621dacfcc 100644 (file)
@@ -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);
                }
        }