mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-11 14:05:12 +00:00
MEDIUM: fd: remove the EV_FD_COND_* primitives
These primitives were initially introduced so that callers were able to conditionally set/disable polling on a file descriptor and check in return what the state was. It's been long since we last had an "if" on this, and all pollers' functions were the same for cond_* and their systematic counter parts, except that this required a check and a specific return value that are not always necessary. So let's simplify the FD API by removing this now unused distinction and by making all specific functions return void.
This commit is contained in:
parent
c76ae33bfc
commit
3788e4c874
@ -73,8 +73,6 @@ void run_poller();
|
||||
#define EV_FD_SET(fd, ev) (cur_poller.set((fd), (ev)))
|
||||
#define EV_FD_CLR(fd, ev) (cur_poller.clr((fd), (ev)))
|
||||
#define EV_FD_ISSET(fd, ev) (cur_poller.is_set((fd), (ev)))
|
||||
#define EV_FD_COND_S(fd, ev) (cur_poller.cond_s((fd), (ev)))
|
||||
#define EV_FD_COND_C(fd, ev) (cur_poller.cond_c((fd), (ev)))
|
||||
#define EV_FD_REM(fd) (cur_poller.rem(fd))
|
||||
#define EV_FD_CLO(fd) (cur_poller.clo(fd))
|
||||
|
||||
|
@ -91,10 +91,6 @@ struct fdinfo {
|
||||
* poller should set it to 100.
|
||||
* - <private> is initialized by the poller's init() function, and cleaned by
|
||||
* the term() function.
|
||||
* - cond_s() checks if fd was not set then sets it and returns 1. Otherwise
|
||||
* it returns 0. It may be the same as set().
|
||||
* - cond_c() checks if fd was set then clears it and returns 1. Otherwise
|
||||
* it returns 0. It may be the same as clr().
|
||||
* - clo() should be used to do indicate the poller that fd will be closed. It
|
||||
* may be the same as rem() on some pollers.
|
||||
* - poll() calls the poller, expiring at <exp>
|
||||
@ -102,10 +98,8 @@ struct fdinfo {
|
||||
struct poller {
|
||||
void *private; /* any private data for the poller */
|
||||
int REGPRM2 (*is_set)(const int fd, int dir); /* check if <fd> is being polled for dir <dir> */
|
||||
int REGPRM2 (*set)(const int fd, int dir); /* set polling on <fd> for <dir> */
|
||||
int REGPRM2 (*clr)(const int fd, int dir); /* clear polling on <fd> for <dir> */
|
||||
int REGPRM2 (*cond_s)(const int fd, int dir); /* set polling on <fd> for <dir> if unset */
|
||||
int REGPRM2 (*cond_c)(const int fd, int dir); /* clear polling on <fd> for <dir> if set */
|
||||
void REGPRM2 (*set)(const int fd, int dir); /* set polling on <fd> for <dir> */
|
||||
void REGPRM2 (*clr)(const int fd, int dir); /* clear polling on <fd> for <dir> */
|
||||
void REGPRM1 (*rem)(const int fd); /* remove any polling on <fd> */
|
||||
void REGPRM1 (*clo)(const int fd); /* mark <fd> as closed */
|
||||
void REGPRM2 (*poll)(struct poller *p, int exp); /* the poller itself */
|
||||
|
@ -147,7 +147,7 @@ REGPRM2 static void alloc_chg_list(const int fd, int old_evt)
|
||||
ptr->prev = old_evt;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
REGPRM2 static void __fd_set(const int fd, int dir)
|
||||
{
|
||||
uint32_t ofs = FD2OFS(fd);
|
||||
uint32_t dmsk = DIR2MSK(dir);
|
||||
@ -156,15 +156,14 @@ REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
old_evt = fd_evts[ofs] >> FD2BIT(fd);
|
||||
old_evt &= 3;
|
||||
if (unlikely(old_evt & dmsk))
|
||||
return 0;
|
||||
return;
|
||||
|
||||
alloc_chg_list(fd, old_evt);
|
||||
dmsk <<= FD2BIT(fd);
|
||||
fd_evts[ofs] |= dmsk;
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
REGPRM2 static void __fd_clr(const int fd, int dir)
|
||||
{
|
||||
uint32_t ofs = FD2OFS(fd);
|
||||
uint32_t dmsk = DIR2MSK(dir);
|
||||
@ -173,12 +172,11 @@ REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
old_evt = fd_evts[ofs] >> FD2BIT(fd);
|
||||
old_evt &= 3;
|
||||
if (unlikely(!(old_evt & dmsk)))
|
||||
return 0;
|
||||
return;
|
||||
|
||||
alloc_chg_list(fd, old_evt);
|
||||
dmsk <<= FD2BIT(fd);
|
||||
fd_evts[ofs] &= ~dmsk;
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGPRM1 static void __fd_rem(int fd)
|
||||
@ -190,7 +188,6 @@ REGPRM1 static void __fd_rem(int fd)
|
||||
|
||||
alloc_chg_list(fd, 0);
|
||||
fd_evts[ofs] &= ~FD2MSK(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -206,7 +203,6 @@ REGPRM1 static void __fd_clo(int fd)
|
||||
ptr->prev = 0;
|
||||
chg_ptr[fd] = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -399,8 +395,8 @@ static void _do_register(void)
|
||||
p->fork = _do_fork;
|
||||
|
||||
p->is_set = __fd_is_set;
|
||||
p->cond_s = p->set = __fd_set;
|
||||
p->cond_c = p->clr = __fd_clr;
|
||||
p->set = __fd_set;
|
||||
p->clr = __fd_clr;
|
||||
p->rem = __fd_rem;
|
||||
p->clo = __fd_clo;
|
||||
}
|
||||
|
@ -60,24 +60,22 @@ REGPRM2 static int __fd_is_set(const int fd, int dir)
|
||||
return FD_ISSET(fd, fd_evts[dir]);
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
REGPRM2 static void __fd_set(const int fd, int dir)
|
||||
{
|
||||
/* if the value was set, do nothing */
|
||||
if (FD_ISSET(fd, fd_evts[dir]))
|
||||
return 0;
|
||||
return;
|
||||
|
||||
FD_SET(fd, fd_evts[dir]);
|
||||
EV_SET(kev, fd, dir2filt[dir], EV_ADD, 0, 0, NULL);
|
||||
kevent(kqueue_fd, kev, 1, NULL, 0, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
REGPRM2 static void __fd_clr(const int fd, int dir)
|
||||
{
|
||||
if (!kqev_del(kev, fd, dir))
|
||||
return 0;
|
||||
return;
|
||||
kevent(kqueue_fd, kev, 1, NULL, 0, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGPRM1 static void __fd_rem(int fd)
|
||||
@ -275,8 +273,8 @@ static void _do_register(void)
|
||||
p->fork = _do_fork;
|
||||
|
||||
p->is_set = __fd_is_set;
|
||||
p->cond_s = p->set = __fd_set;
|
||||
p->cond_c = p->clr = __fd_clr;
|
||||
p->set = __fd_set;
|
||||
p->clr = __fd_clr;
|
||||
p->rem = __fd_rem;
|
||||
p->clo = __fd_clo;
|
||||
}
|
||||
|
@ -43,34 +43,14 @@ REGPRM2 static int __fd_is_set(const int fd, int dir)
|
||||
return FD_ISSET(fd, fd_evts[dir]);
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
REGPRM2 static void __fd_set(const int fd, int dir)
|
||||
{
|
||||
FD_SET(fd, fd_evts[dir]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
REGPRM2 static void __fd_clr(const int fd, int dir)
|
||||
{
|
||||
FD_CLR(fd, fd_evts[dir]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_cond_s(const int fd, int dir)
|
||||
{
|
||||
int ret;
|
||||
ret = !FD_ISSET(fd, fd_evts[dir]);
|
||||
if (ret)
|
||||
FD_SET(fd, fd_evts[dir]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_cond_c(const int fd, int dir)
|
||||
{
|
||||
int ret;
|
||||
ret = FD_ISSET(fd, fd_evts[dir]);
|
||||
if (ret)
|
||||
FD_CLR(fd, fd_evts[dir]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
REGPRM1 static void __fd_rem(const int fd)
|
||||
@ -252,8 +232,6 @@ static void _do_register(void)
|
||||
p->set = __fd_set;
|
||||
p->clr = __fd_clr;
|
||||
p->clo = p->rem = __fd_rem;
|
||||
p->cond_s = __fd_cond_s;
|
||||
p->cond_c = __fd_cond_c;
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,34 +40,14 @@ REGPRM2 static int __fd_is_set(const int fd, int dir)
|
||||
return FD_ISSET(fd, fd_evts[dir]);
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
REGPRM2 static void __fd_set(const int fd, int dir)
|
||||
{
|
||||
FD_SET(fd, fd_evts[dir]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
REGPRM2 static void __fd_clr(const int fd, int dir)
|
||||
{
|
||||
FD_CLR(fd, fd_evts[dir]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_cond_s(const int fd, int dir)
|
||||
{
|
||||
int ret;
|
||||
ret = !FD_ISSET(fd, fd_evts[dir]);
|
||||
if (ret)
|
||||
FD_SET(fd, fd_evts[dir]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_cond_c(const int fd, int dir)
|
||||
{
|
||||
int ret;
|
||||
ret = FD_ISSET(fd, fd_evts[dir]);
|
||||
if (ret)
|
||||
FD_CLR(fd, fd_evts[dir]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
REGPRM1 static void __fd_rem(int fd)
|
||||
@ -249,8 +229,6 @@ static void _do_register(void)
|
||||
p->set = __fd_set;
|
||||
p->clr = __fd_clr;
|
||||
p->clo = p->rem = __fd_rem;
|
||||
p->cond_s = __fd_cond_s;
|
||||
p->cond_c = __fd_cond_c;
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,7 +215,7 @@ REGPRM2 static int __fd_is_set(const int fd, int dir)
|
||||
* Don't worry about the strange constructs in __fd_set/__fd_clr, they are
|
||||
* designed like this in order to reduce the number of jumps (verified).
|
||||
*/
|
||||
REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
REGPRM2 static void __fd_set(const int fd, int dir)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@ -229,15 +229,14 @@ REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
|
||||
if (i != FD_EV_STOP) {
|
||||
if (unlikely(i != FD_EV_IDLE))
|
||||
return 0;
|
||||
return;
|
||||
// switch to SPEC state and allocate a SPEC entry.
|
||||
alloc_spec_entry(fd);
|
||||
}
|
||||
fdtab[fd].spec.e ^= (unsigned int)(FD_EV_IN_SL << dir);
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
REGPRM2 static void __fd_clr(const int fd, int dir)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@ -251,7 +250,7 @@ REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
|
||||
if (i != FD_EV_SPEC) {
|
||||
if (unlikely(i != FD_EV_WAIT))
|
||||
return 0;
|
||||
return;
|
||||
// switch to STOP state
|
||||
/* We will create a queue entry for this one because we want to
|
||||
* process it later in order to merge it with other events on
|
||||
@ -260,7 +259,6 @@ REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
alloc_spec_entry(fd);
|
||||
}
|
||||
fdtab[fd].spec.e ^= (unsigned int)(FD_EV_IN_SL << dir);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* normally unused */
|
||||
@ -593,8 +591,8 @@ static void _do_register(void)
|
||||
p->fork = _do_fork;
|
||||
|
||||
p->is_set = __fd_is_set;
|
||||
p->cond_s = p->set = __fd_set;
|
||||
p->cond_c = p->clr = __fd_clr;
|
||||
p->set = __fd_set;
|
||||
p->clr = __fd_clr;
|
||||
p->rem = __fd_rem;
|
||||
p->clo = __fd_clo;
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ static void sock_raw_data_finish(struct stream_interface *si)
|
||||
if (!(si->flags & SI_FL_WAIT_ROOM)) {
|
||||
if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL)
|
||||
si->flags |= SI_FL_WAIT_ROOM;
|
||||
EV_FD_COND_C(fd, DIR_RD);
|
||||
EV_FD_CLR(fd, DIR_RD);
|
||||
ib->rex = TICK_ETERNITY;
|
||||
}
|
||||
}
|
||||
@ -804,7 +804,7 @@ static void sock_raw_data_finish(struct stream_interface *si)
|
||||
* have updated it if there has been a completed I/O.
|
||||
*/
|
||||
si->flags &= ~SI_FL_WAIT_ROOM;
|
||||
EV_FD_COND_S(fd, DIR_RD);
|
||||
EV_FD_SET(fd, DIR_RD);
|
||||
if (!(ib->flags & (BF_READ_NOEXP|BF_DONT_READ)) && !tick_isset(ib->rex))
|
||||
ib->rex = tick_add_ifset(now_ms, ib->rto);
|
||||
}
|
||||
@ -818,7 +818,7 @@ static void sock_raw_data_finish(struct stream_interface *si)
|
||||
if (!(si->flags & SI_FL_WAIT_DATA)) {
|
||||
if ((ob->flags & (BF_FULL|BF_HIJACK|BF_SHUTW_NOW)) == 0)
|
||||
si->flags |= SI_FL_WAIT_DATA;
|
||||
EV_FD_COND_C(fd, DIR_WR);
|
||||
EV_FD_CLR(fd, DIR_WR);
|
||||
ob->wex = TICK_ETERNITY;
|
||||
}
|
||||
}
|
||||
@ -829,7 +829,7 @@ static void sock_raw_data_finish(struct stream_interface *si)
|
||||
* have updated it if there has been a completed I/O.
|
||||
*/
|
||||
si->flags &= ~SI_FL_WAIT_DATA;
|
||||
EV_FD_COND_S(fd, DIR_WR);
|
||||
EV_FD_SET(fd, DIR_WR);
|
||||
if (!tick_isset(ob->wex)) {
|
||||
ob->wex = tick_add_ifset(now_ms, ob->wto);
|
||||
if (tick_isset(ib->rex) && !(si->flags & SI_FL_INDEP_STR)) {
|
||||
@ -870,12 +870,12 @@ static void sock_raw_chk_rcv(struct stream_interface *si)
|
||||
/* stop reading */
|
||||
if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL)
|
||||
si->flags |= SI_FL_WAIT_ROOM;
|
||||
EV_FD_COND_C(si_fd(si), DIR_RD);
|
||||
EV_FD_CLR(si_fd(si), DIR_RD);
|
||||
}
|
||||
else {
|
||||
/* (re)start reading */
|
||||
si->flags &= ~SI_FL_WAIT_ROOM;
|
||||
EV_FD_COND_S(si_fd(si), DIR_RD);
|
||||
EV_FD_SET(si_fd(si), DIR_RD);
|
||||
}
|
||||
}
|
||||
|
||||
@ -951,7 +951,7 @@ static void sock_raw_chk_snd(struct stream_interface *si)
|
||||
/* Otherwise there are remaining data to be sent in the buffer,
|
||||
* which means we have to poll before doing so.
|
||||
*/
|
||||
EV_FD_COND_S(si_fd(si), DIR_WR);
|
||||
EV_FD_SET(si_fd(si), DIR_WR);
|
||||
si->flags &= ~SI_FL_WAIT_DATA;
|
||||
if (!tick_isset(ob->wex))
|
||||
ob->wex = tick_add_ifset(now_ms, ob->wto);
|
||||
|
Loading…
Reference in New Issue
Block a user