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.
This commit is contained in:
Willy Tarreau 2018-01-25 16:37:04 +01:00
parent 745c60eac6
commit 322e6c7e73
2 changed files with 16 additions and 10 deletions

View File

@ -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 */

View File

@ -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);