MINOR: fd: make fd_insert() apply the thread mask itself
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.
diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h
index 6763200..b9f3803 100644
--- a/include/haproxy/fd.h
+++ b/include/haproxy/fd.h
@@ -322,7 +322,9 @@
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 @@
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;
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index 234ec10..0798283 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -157,7 +157,7 @@
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:
diff --git a/src/sock_inet.c b/src/sock_inet.c
index bc3b762..9e1451a 100644
--- a/src/sock_inet.c
+++ b/src/sock_inet.c
@@ -390,7 +390,7 @@
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))
diff --git a/src/sock_unix.c b/src/sock_unix.c
index 6544ccf..026d86c 100644
--- a/src/sock_unix.c
+++ b/src/sock_unix.c
@@ -284,7 +284,7 @@
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))