]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: update flags only once in fd_update_events()
authorWilly Tarreau <w@1wt.eu>
Thu, 29 Jul 2021 06:04:00 +0000 (08:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 30 Jul 2021 15:41:55 +0000 (17:41 +0200)
Since 2.4 with commit f50906519 ("MEDIUM: fd: merge fdtab[].ev and state
for FD_EV_* and FD_POLL_* into state") we can merge all flag updates at
once in fd_update_events(). Previously this was performed in 1 to 3 steps,
setting the polling state, then setting READY_R if in/err/hup, and setting
READY_W if out/err. But since the commit above, all flags are stored
together in the same structure field that is being updated with the new
flags, thus we can simply update the flags altogether and avoid multiple
atomic operations. This even removes the need for atomic ops for FDs that
are not shared.

include/haproxy/fd.h

index 66a9aea8f9cf009b47f5ca6b7e07846dbe44dab9..e1a80d735252fb2edfd13b0660a1601d66b5040c 100644 (file)
@@ -397,6 +397,12 @@ static inline void fd_update_events(int fd, uint evts)
                must_stop = FD_POLL_OUT;
        }
 
+       if (new_flags & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
+               new_flags |= FD_EV_READY_R;
+
+       if (new_flags & (FD_POLL_OUT | FD_POLL_ERR))
+               new_flags |= FD_EV_READY_W;
+
        old = fdtab[fd].state;
        new = (old & ~FD_POLL_UPDT_MASK) | new_flags;
 
@@ -409,12 +415,6 @@ static inline void fd_update_events(int fd, uint evts)
                        fdtab[fd].state = new;
        }
 
-       if (fdtab[fd].state & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
-               fd_may_recv(fd);
-
-       if (fdtab[fd].state & (FD_POLL_OUT | FD_POLL_ERR))
-               fd_may_send(fd);
-
        if (fdtab[fd].iocb && fd_active(fd)) {
                fdtab[fd].iocb(fd);
        }