]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: fd: mark the FD as ready when it's inserted
authorWilly Tarreau <w@1wt.eu>
Thu, 5 Sep 2019 14:30:39 +0000 (16:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 Sep 2019 15:50:36 +0000 (17:50 +0200)
Given that all our I/Os are now directed from top to bottom and not the
opposite way around, and the FD cache was removed, it doesn't make sense
anymore to create FDs that are marked not ready since this would prevent
the first accesses unless the caller explicitly does an fd_may_recv()
which is not expected to be its job (which conn_ctrl_init() has to do
by the way). Let's move this into fd_insert() instead, and have a single
atomic operation for both directions via fd_may_both().

include/proto/connection.h
include/proto/fd.h

index 7e4cb03bfaffd801332de2aded83927f8d87e9f9..b1d8638e967dccbe4cc413dde59984e6c4e02587 100644 (file)
@@ -123,9 +123,6 @@ static inline void conn_ctrl_init(struct connection *conn)
                int fd = conn->handle.fd;
 
                fd_insert(fd, conn, conn_fd_handler, tid_bit);
-               /* mark the fd as ready so as not to needlessly poll at the beginning */
-               fd_may_recv(fd);
-               fd_may_send(fd);
                conn->flags |= CO_FL_CTRL_READY;
        }
 }
index 4b932357ff9bb162d695fb7afd7982062685046d..747b34f78e2cd14a31ff1e0a168246d7a3326eef 100644 (file)
@@ -241,6 +241,14 @@ static inline void fd_may_recv(const int fd)
                return;
 }
 
+/* Report that FD <fd> may receive and send without polling. Used at FD
+ * initialization.
+ */
+static inline void fd_may_both(const int fd)
+{
+       HA_ATOMIC_OR(&fdtab[fd].state, FD_EV_READY_RW);
+}
+
 /* Disable readiness when active. This is useful to interrupt reading when it
  * is suspected that the end of data might have been reached (eg: short read).
  * This can only be done using level-triggered pollers, so if any edge-triggered
@@ -339,6 +347,8 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned
         */
        if (locked)
                HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
+       /* the two directions are ready until proven otherwise */
+       fd_may_both(fd);
        _HA_ATOMIC_ADD(&ha_used_fds, 1);
 }