]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: fd: remove the EV_FD_COND_* primitives
authorWilly Tarreau <wtarreau@exceliance.fr>
Mon, 30 Jul 2012 12:29:35 +0000 (14:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:53:10 +0000 (21:53 +0200)
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.

include/proto/fd.h
include/types/fd.h
src/ev_epoll.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c
src/ev_sepoll.c
src/sock_raw.c

index 1cba33b7f1edc913de1dbe0f12db2ddba3edef5d..ffbb8e180d3ffa2328da6503b5de83d42ac766ae 100644 (file)
@@ -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))
 
index 684b77abd9cb481aad349bba721020fa716312f3..2e350b82896876425d04aa32bc9c06233562de74 100644 (file)
@@ -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 */
index 63782d3ef292ab19a797d7d00af859df9a2a7210..6c8408bc0d8a8d31ff806dcf193749de0b821a3f 100644 (file)
@@ -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;
 }
index 3d12e36bf045f7a1400c1aaeca30df97e09418f8..4bfbf1bf888b9bfb0bdb4ed953740230e3d848d8 100644 (file)
@@ -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;
 }
index cb210f72010ca2be3241c527dbc5c3afbde0868b..f72dfe286731e9703bc8e55a85a54ec0186b42be 100644 (file)
@@ -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;
 }
 
 
index c5d39366991cee6c7c58399b481953b3b2c0a8fe..cf4526216bfe403c39e3cd319f4ed35eb10a4c6a 100644 (file)
@@ -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;
 }
 
 
index 5d93bf2a989e2dab0c17e9c629bde7d2e8a4d5b3..62ee1156e22638751664b3087641c160479f1f93 100644 (file)
@@ -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;
 }
index 8136d601ca346dfefd71df8aa27d7a07f2916a0c..1532e762d7b6aa4296a0407eefeb267ec00bc893 100644 (file)
@@ -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);