From 322e6c7e73191ead3b868c683bf76b373f522736 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 25 Jan 2018 16:37:04 +0100 Subject: [PATCH] MINOR: fd: move the hap_fd_{clr,set,isset} functions to fd.h These functions were created for poll() in 1.5-dev18 (commit 80da05a4) to replace the previous FD_{CLR,SET,ISSET} that were shared with select() because some libcs enforce a limit on FD_SET. But FD_SET doesn't seem to be universally MT-safe, requiring locks in the select() code that are not needed in the poll code. So let's move back to the initial situation where we used to only use bit fields, since that has been in use since day one without a problem, and let's use these hap_fd_* functions instead of FD_*. This patch only moves the functions to fd.h and revives hap_fd_isset() that was recently removed to kill an "unused" warning. --- include/proto/fd.h | 16 ++++++++++++++++ src/ev_poll.c | 10 ---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/proto/fd.h b/include/proto/fd.h index 5885d0cc9c..fcf026e2ea 100644 --- a/include/proto/fd.h +++ b/include/proto/fd.h @@ -409,6 +409,22 @@ static inline void fd_insert(int fd, unsigned long thread_mask) HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock); } +/* These are replacements for FD_SET, FD_CLR, FD_ISSET, working on uints */ +static inline void hap_fd_set(int fd, unsigned int *evts) +{ + evts[fd / (8*sizeof(*evts))] |= 1U << (fd & (8*sizeof(*evts) - 1)); +} + +static inline void hap_fd_clr(int fd, unsigned int *evts) +{ + evts[fd / (8*sizeof(*evts))] &= ~(1U << (fd & (8*sizeof(*evts) - 1))); +} + +static inline unsigned int hap_fd_isset(int fd, unsigned int *evts) +{ + return evts[fd / (8*sizeof(*evts))] & (1U << (fd & (8*sizeof(*evts) - 1))); +} + #endif /* _PROTO_FD_H */ diff --git a/src/ev_poll.c b/src/ev_poll.c index 715314cda9..b8ef537943 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -39,16 +39,6 @@ static unsigned int *fd_evts[2]; static THREAD_LOCAL int nbfd = 0; static THREAD_LOCAL struct pollfd *poll_events = NULL; -static inline void hap_fd_set(int fd, unsigned int *evts) -{ - evts[fd / (8*sizeof(*evts))] |= 1U << (fd & (8*sizeof(*evts) - 1)); -} - -static inline void hap_fd_clr(int fd, unsigned int *evts) -{ - evts[fd / (8*sizeof(*evts))] &= ~(1U << (fd & (8*sizeof(*evts) - 1))); -} - REGPRM1 static void __fd_clo(int fd) { HA_SPIN_LOCK(POLL_LOCK, &poll_lock);