]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: move .initialized into fdtab[].state
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Apr 2021 15:57:12 +0000 (17:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 16:09:08 +0000 (18:09 +0200)
No need to keep this flag apart any more, let's merge it into the global
state. The bit was not cleared in fd_insert() because the only user is
the function used to create and atomically send a log message to a pipe
FD, which never registers the fd. Here we clear it nevertheless for the
sake of clarity.

Note that with an extra cleaning pass we could have a bit number
here and simply use a BTS to test and set it.

include/haproxy/fd-t.h
src/fd.c

index 1f558400637e8e925781e2f47acd578a614c2c48..cfcde398b2c756627f5f1b3eb9daf7732aeb7f31 100644 (file)
@@ -65,6 +65,7 @@ enum {
 /* info/config bits */
 #define FD_LINGER_RISK_BIT 16  /* must kill lingering before closing */
 #define FD_CLONED_BIT      17  /* cloned socket, requires EPOLL_CTL_DEL on close */
+#define FD_INITIALIZED_BIT 18  /* init phase was done (e.g. output pipe set non-blocking) */
 
 
 /* and flag values */
@@ -101,6 +102,7 @@ enum {
 /* information/configuration flags */
 #define FD_LINGER_RISK      (1U << FD_LINGER_RISK_BIT)
 #define FD_CLONED           (1U << FD_CLONED_BIT)
+#define FD_INITIALIZED      (1U << FD_INITIALIZED_BIT)
 
 /* This is the value used to mark a file descriptor as dead. This value is
  * negative, this is important so that tests on fd < 0 properly match. It
@@ -149,7 +151,6 @@ struct fdtab {
        void (*iocb)(int fd);                /* I/O handler */
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        unsigned int state;                  /* FD state for read and write directions (FD_EV_*) + FD_POLL_* */
-       unsigned char initialized:1;         /* 1 if init phase was done on this fd (e.g. set non-blocking) */
        unsigned char et_possible:1;         /* 1 if edge-triggered is possible on this FD */
        unsigned char exported:1;            /* 1 if the FD is exported and must not be closed */
 #ifdef DEBUG_FD
index 64e4e9cc0e1d7fd007dc8e968656ba8d9f054780..fe9db237c4dd80d972027a7c0b1365987bbada39 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -514,8 +514,8 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t
                ha_thread_relax();
        }
 
-       if (unlikely(!fdtab[fd].initialized)) {
-               fdtab[fd].initialized = 1;
+       if (unlikely(!(fdtab[fd].state & FD_INITIALIZED))) {
+               HA_ATOMIC_OR(&fdtab[fd].state, FD_INITIALIZED);
                if (!isatty(fd))
                        fcntl(fd, F_SETFL, O_NONBLOCK);
        }