]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: make fd_insert() apply the thread mask itself
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Jul 2022 09:27:42 +0000 (11:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Jul 2022 17:58:06 +0000 (19:58 +0200)
It's a bit ugly to see that half of the callers of fd_insert() have to
apply all_threads_mask themselves to the bit field they're passing,
because usually it comes from a listener that may have other bits set.
Let's make the function apply the mask itself.

include/haproxy/fd.h
src/proto_sockpair.c
src/sock_inet.c
src/sock_unix.c

index 6763200e3802fe3c7df838b45982d1035d12742b..b9f3803b49d238220f1f1f531034704a53e18c17 100644 (file)
@@ -322,7 +322,9 @@ static inline long fd_clr_running(int fd)
        return _HA_ATOMIC_AND_FETCH(&fdtab[fd].running_mask, ~tid_bit);
 }
 
-/* Prepares <fd> for being polled */
+/* Prepares <fd> for being polled on all permitted threads (these will then be
+ * refined to only cover running ones).
+*/
 static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned long thread_mask)
 {
        extern void sock_conn_iocb(int);
@@ -333,6 +335,8 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned
        BUG_ON(fd < 0 || fd >= global.maxsock);
        BUG_ON(fdtab[fd].owner != NULL);
        BUG_ON(fdtab[fd].state != 0);
+
+       thread_mask &= all_threads_mask;
        BUG_ON(thread_mask == 0);
 
        fdtab[fd].owner = owner;
index 234ec108a7e53032397d60bd861e316d286d3c57..0798283b93a071f35d07416a1bfdfb0202df1a5f 100644 (file)
@@ -157,7 +157,7 @@ int sockpair_bind_receiver(struct receiver *rx, char **errmsg)
 
        rx->flags |= RX_F_BOUND;
 
-       fd_insert(rx->fd, rx->owner, rx->iocb, rx->bind_thread & all_threads_mask);
+       fd_insert(rx->fd, rx->owner, rx->iocb, rx->bind_thread);
        return err;
 
  bind_return:
index bc3b762f7aa2cc7d5805156a9f6634b2ec7384d1..9e1451ad9b745db6dfac3fbbd74124a42a5aa541 100644 (file)
@@ -390,7 +390,7 @@ int sock_inet_bind_receiver(struct receiver *rx, char **errmsg)
        rx->fd = fd;
        rx->flags |= RX_F_BOUND;
 
-       fd_insert(fd, rx->owner, rx->iocb, rx->bind_thread & all_threads_mask);
+       fd_insert(fd, rx->owner, rx->iocb, rx->bind_thread);
 
        /* for now, all regularly bound TCP listeners are exportable */
        if (!(rx->flags & RX_F_INHERITED))
index 6544ccf0912cf428bc29b174906d2b6e4d354adf..026d86c57faac33f403854ca643270090520f5dc 100644 (file)
@@ -284,7 +284,7 @@ int sock_unix_bind_receiver(struct receiver *rx, char **errmsg)
        rx->fd = fd;
        rx->flags |= RX_F_BOUND;
 
-       fd_insert(fd, rx->owner, rx->iocb, rx->bind_thread & all_threads_mask);
+       fd_insert(fd, rx->owner, rx->iocb, rx->bind_thread);
 
        /* for now, all regularly bound TCP listeners are exportable */
        if (!(rx->flags & RX_F_INHERITED))