]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] pollers: store the events in arrays
authorWilly Tarreau <w@1wt.eu>
Sun, 8 Apr 2007 15:42:27 +0000 (17:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 8 Apr 2007 15:42:27 +0000 (17:42 +0200)
Instead of managing StaticReadEvent/StaticWriteEvent, use evts[dir]

src/ev_epoll.c
src/ev_poll.c
src/ev_select.c

index ff49505e28fe896ca642d8b674b6a85f1faa83f9..65b3d74055a544d4f40e9646488787841d6d19be 100644 (file)
@@ -34,8 +34,8 @@ _syscall4 (int, epoll_wait, int, epfd, struct epoll_event *, events, int, maxeve
 #endif
 
 
-static fd_set *StaticReadEvent, *StaticWriteEvent;
-static fd_set *PrevReadEvent, *PrevWriteEvent;
+static fd_set *fd_evts[2];
+static fd_set *old_evts[2];
 
 /* private data */
 static struct epoll_event *epoll_events;
@@ -49,79 +49,49 @@ static int epoll_fd;
  */
 REGPRM2 static int __fd_isset(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       return FD_ISSET(fd, ev);
+       return FD_ISSET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_set(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_SET(fd, ev);
+       FD_SET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_clr(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_CLR(fd, ev);
+       FD_CLR(fd, fd_evts[dir]);
 }
 
 REGPRM2 static int __fd_cond_s(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = !FD_ISSET(fd, ev);
+       ret = !FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_SET(fd, ev);
+               FD_SET(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM2 static int __fd_cond_c(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = FD_ISSET(fd, ev);
+       ret = FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_CLR(fd, ev);
+               FD_CLR(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM1 static void __fd_rem(const int fd)
 {
-       FD_CLR(fd, StaticReadEvent);
-       FD_CLR(fd, StaticWriteEvent);
+       FD_CLR(fd, fd_evts[DIR_RD]);
+       FD_CLR(fd, fd_evts[DIR_WR]);
 }
 
 REGPRM1 static void __fd_clo(const int fd)
 {
-       FD_CLR(fd, StaticReadEvent);
-       FD_CLR(fd, StaticWriteEvent);
-       FD_CLR(fd, PrevReadEvent);
-       FD_CLR(fd, PrevWriteEvent);
+       FD_CLR(fd, fd_evts[DIR_RD]);
+       FD_CLR(fd, fd_evts[DIR_WR]);
+       FD_CLR(fd, old_evts[DIR_RD]);
+       FD_CLR(fd, old_evts[DIR_WR]);
 }
 
 
@@ -149,26 +119,26 @@ REGPRM1 static int epoll_init(struct poller *p)
        if (epoll_events == NULL)
                goto fail_ee;
 
-       if ((PrevReadEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((old_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_prevt;
 
-       if ((PrevWriteEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((old_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_pwevt;
                
-       if ((StaticReadEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_srevt;
 
-       if ((StaticWriteEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_swevt;
 
        return 1;
 
  fail_swevt:
-       free(StaticReadEvent);
+       free(fd_evts[DIR_RD]);
  fail_srevt:
-       free(PrevWriteEvent);
+       free(old_evts[DIR_WR]);
  fail_pwevt:
-       free(PrevReadEvent);
+       free(old_evts[DIR_RD]);
  fail_prevt:
        free(epoll_events);
  fail_ee:
@@ -185,17 +155,17 @@ REGPRM1 static int epoll_init(struct poller *p)
  */
 REGPRM1 static void epoll_term(struct poller *p)
 {
-       if (StaticWriteEvent)
-               free(StaticWriteEvent);
+       if (fd_evts[DIR_WR])
+               free(fd_evts[DIR_WR]);
 
-       if (StaticReadEvent)
-               free(StaticReadEvent);
+       if (fd_evts[DIR_RD])
+               free(fd_evts[DIR_RD]);
 
-       if (PrevWriteEvent)
-               free(PrevWriteEvent);
+       if (old_evts[DIR_WR])
+               free(old_evts[DIR_WR]);
 
-       if (PrevReadEvent)
-               free(PrevReadEvent);
+       if (old_evts[DIR_RD])
+               free(old_evts[DIR_RD]);
 
        if (epoll_events)
                free(epoll_events);
@@ -222,8 +192,8 @@ REGPRM2 static void epoll_poll(struct poller *p, int wait_time)
 
        for (fds = 0; (fds << INTBITS) < maxfd; fds++) {
          
-               rn = ((int*)StaticReadEvent)[fds];  ro = ((int*)PrevReadEvent)[fds];
-               wn = ((int*)StaticWriteEvent)[fds]; wo = ((int*)PrevWriteEvent)[fds];
+               rn = ((int*)fd_evts[DIR_RD])[fds];  ro = ((int*)old_evts[DIR_RD])[fds];
+               wn = ((int*)fd_evts[DIR_WR])[fds]; wo = ((int*)old_evts[DIR_WR])[fds];
          
                if ((ro^rn) | (wo^wn)) {
                        for (count = 0, fd = fds << INTBITS; count < (1<<INTBITS) && fd < maxfd; count++, fd++) {
@@ -243,10 +213,10 @@ REGPRM2 static void epoll_poll(struct poller *p, int wait_time)
                                sw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
 #endif
 #else
-                               pr = FD_ISSET(fd, PrevReadEvent);
-                               pw = FD_ISSET(fd, PrevWriteEvent);
-                               sr = FD_ISSET(fd, StaticReadEvent);
-                               sw = FD_ISSET(fd, StaticWriteEvent);
+                               pr = FD_ISSET(fd, old_evts[DIR_RD]);
+                               pw = FD_ISSET(fd, old_evts[DIR_WR]);
+                               sr = FD_ISSET(fd, fd_evts[DIR_RD]);
+                               sw = FD_ISSET(fd, fd_evts[DIR_WR]);
 #endif
                                if (!((sr^pr) | (sw^pw)))
                                        continue;
@@ -296,8 +266,8 @@ REGPRM2 static void epoll_poll(struct poller *p, int wait_time)
                                }
 #endif // EPOLL_CTL_MOD_WORKAROUND
                        }
-                       ((int*)PrevReadEvent)[fds] = rn;
-                       ((int*)PrevWriteEvent)[fds] = wn;
+                       ((int*)old_evts[DIR_RD])[fds] = rn;
+                       ((int*)old_evts[DIR_WR])[fds] = wn;
                }                 
        }
       
@@ -308,14 +278,14 @@ REGPRM2 static void epoll_poll(struct poller *p, int wait_time)
        for (count = 0; count < status; count++) {
                fd = epoll_events[count].data.fd;
 
-               if (FD_ISSET(fd, StaticReadEvent)) {
+               if (FD_ISSET(fd, fd_evts[DIR_RD])) {
                        if (fdtab[fd].state == FD_STCLOSE)
                                continue;
                        if (epoll_events[count].events & ( EPOLLIN | EPOLLERR | EPOLLHUP ))
                                fdtab[fd].cb[DIR_RD].f(fd);
                }
 
-               if (FD_ISSET(fd, StaticWriteEvent)) {
+               if (FD_ISSET(fd, fd_evts[DIR_WR])) {
                        if (fdtab[fd].state == FD_STCLOSE)
                                continue;
                        if (epoll_events[count].events & ( EPOLLOUT | EPOLLERR | EPOLLHUP ))
index 2d6d98474c4813f076bb570bb10465b23395da88..d43fa0c6cfd0aa7560b5b8752df70e01f37037cb 100644 (file)
@@ -26,7 +26,7 @@
 #include <proto/task.h>
 
 
-static fd_set *StaticReadEvent, *StaticWriteEvent;
+static fd_set *fd_evts[2];
 
 /* private data */
 static struct pollfd *poll_events = NULL;
@@ -39,71 +39,41 @@ static struct pollfd *poll_events = NULL;
  */
 REGPRM2 static int __fd_isset(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       return FD_ISSET(fd, ev);
+       return FD_ISSET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_set(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_SET(fd, ev);
+       FD_SET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_clr(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_CLR(fd, ev);
+       FD_CLR(fd, fd_evts[dir]);
 }
 
 REGPRM2 static int __fd_cond_s(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = !FD_ISSET(fd, ev);
+       ret = !FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_SET(fd, ev);
+               FD_SET(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM2 static int __fd_cond_c(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = FD_ISSET(fd, ev);
+       ret = FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_CLR(fd, ev);
+               FD_CLR(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM1 static void __fd_rem(const int fd)
 {
-       FD_CLR(fd, StaticReadEvent);
-       FD_CLR(fd, StaticWriteEvent);
+       FD_CLR(fd, fd_evts[DIR_RD]);
+       FD_CLR(fd, fd_evts[DIR_WR]);
 }
 
 
@@ -127,16 +97,16 @@ REGPRM1 static int poll_init(struct poller *p)
        if (poll_events == NULL)
                goto fail_pe;
                
-       if ((StaticReadEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_srevt;
 
-       if ((StaticWriteEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_swevt;
 
        return 1;
 
  fail_swevt:
-       free(StaticReadEvent);
+       free(fd_evts[DIR_RD]);
  fail_srevt:
        free(poll_events);
  fail_pe:
@@ -150,10 +120,10 @@ REGPRM1 static int poll_init(struct poller *p)
  */
 REGPRM1 static void poll_term(struct poller *p)
 {
-       if (StaticWriteEvent)
-               free(StaticWriteEvent);
-       if (StaticReadEvent)
-               free(StaticReadEvent);
+       if (fd_evts[DIR_WR])
+               free(fd_evts[DIR_WR]);
+       if (fd_evts[DIR_RD])
+               free(fd_evts[DIR_RD]);
        if (poll_events)
                free(poll_events);
        p->private = NULL;
@@ -175,8 +145,8 @@ REGPRM2 static void poll_poll(struct poller *p, int wait_time)
        nbfd = 0;
        for (fds = 0; (fds << INTBITS) < maxfd; fds++) {
 
-               rn = ((int*)StaticReadEvent)[fds];
-               wn = ((int*)StaticWriteEvent)[fds];
+               rn = ((int*)fd_evts[DIR_RD])[fds];
+               wn = ((int*)fd_evts[DIR_WR])[fds];
          
                if ((rn|wn)) {
                        for (count = 0, fd = fds << INTBITS; count < (1<<INTBITS) && fd < maxfd; count++, fd++) {
@@ -192,8 +162,8 @@ REGPRM2 static void poll_poll(struct poller *p, int wait_time)
                                sw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
 #endif
 #else
-                               sr = FD_ISSET(fd, StaticReadEvent);
-                               sw = FD_ISSET(fd, StaticWriteEvent);
+                               sr = FD_ISSET(fd, fd_evts[DIR_RD]);
+                               sw = FD_ISSET(fd, fd_evts[DIR_WR]);
 #endif
                                if ((sr|sw)) {
                                        poll_events[nbfd].fd = fd;
@@ -217,14 +187,14 @@ REGPRM2 static void poll_poll(struct poller *p, int wait_time)
                /* ok, we found one active fd */
                status--;
 
-               if (FD_ISSET(fd, StaticReadEvent)) {
+               if (FD_ISSET(fd, fd_evts[DIR_RD])) {
                        if (fdtab[fd].state == FD_STCLOSE)
                                continue;
                        if (poll_events[count].revents & ( POLLIN | POLLERR | POLLHUP ))
                                fdtab[fd].cb[DIR_RD].f(fd);
                }
          
-               if (FD_ISSET(fd, StaticWriteEvent)) {
+               if (FD_ISSET(fd, fd_evts[DIR_WR])) {
                        if (fdtab[fd].state == FD_STCLOSE)
                                continue;
                        if (poll_events[count].revents & ( POLLOUT | POLLERR | POLLHUP ))
index b1cd44ef3e8e18379b24433746d43d53a4833c9a..1ab7119bf62ab65ba96522a39fb341d459f6ec62 100644 (file)
@@ -26,8 +26,8 @@
 #include <proto/task.h>
 
 
-static fd_set *ReadEvent, *WriteEvent;
-static fd_set *StaticReadEvent, *StaticWriteEvent;
+static fd_set *fd_evts[2];
+static fd_set *tmp_evts[2];
 
 
 /*
@@ -37,74 +37,45 @@ static fd_set *StaticReadEvent, *StaticWriteEvent;
  */
 REGPRM2 static int __fd_isset(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       return FD_ISSET(fd, ev);
+       return FD_ISSET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_set(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_SET(fd, ev);
+       FD_SET(fd, fd_evts[dir]);
 }
 
 REGPRM2 static void __fd_clr(const int fd, const int dir)
 {
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       FD_CLR(fd, ev);
+       FD_CLR(fd, fd_evts[dir]);
 }
 
 REGPRM2 static int __fd_cond_s(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = !FD_ISSET(fd, ev);
+       ret = !FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_SET(fd, ev);
+               FD_SET(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM2 static int __fd_cond_c(const int fd, const int dir)
 {
        int ret;
-       fd_set *ev;
-       if (dir == DIR_RD)
-               ev = StaticReadEvent;
-       else
-               ev = StaticWriteEvent;
-
-       ret = FD_ISSET(fd, ev);
+       ret = FD_ISSET(fd, fd_evts[dir]);
        if (ret)
-               FD_CLR(fd, ev);
+               FD_CLR(fd, fd_evts[dir]);
        return ret;
 }
 
 REGPRM1 static void __fd_rem(const int fd)
 {
-       FD_CLR(fd, StaticReadEvent);
-       FD_CLR(fd, StaticWriteEvent);
+       FD_CLR(fd, fd_evts[DIR_RD]);
+       FD_CLR(fd, fd_evts[DIR_WR]);
 }
 
 
+
 /*
  * Initialization of the select() poller.
  * Returns 0 in case of failure, non-zero in case of success. If it fails, it
@@ -118,26 +89,26 @@ REGPRM1 static int select_init(struct poller *p)
        p->private = NULL;
        fd_set_bytes = sizeof(fd_set) * (global.maxsock + FD_SETSIZE - 1) / FD_SETSIZE;
 
-       if ((ReadEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((tmp_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_revt;
                
-       if ((WriteEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((tmp_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_wevt;
 
-       if ((StaticReadEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_RD] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_srevt;
 
-       if ((StaticWriteEvent = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
+       if ((fd_evts[DIR_WR] = (fd_set *)calloc(1, fd_set_bytes)) == NULL)
                goto fail_swevt;
 
        return 1;
 
  fail_swevt:
-       free(StaticReadEvent);
+       free(fd_evts[DIR_RD]);
  fail_srevt:
-       free(WriteEvent);
+       free(tmp_evts[DIR_WR]);
  fail_wevt:
-       free(ReadEvent);
+       free(tmp_evts[DIR_RD]);
  fail_revt:
        p->pref = 0;
        return 0;
@@ -149,14 +120,14 @@ REGPRM1 static int select_init(struct poller *p)
  */
 REGPRM1 static void select_term(struct poller *p)
 {
-       if (StaticWriteEvent)
-               free(StaticWriteEvent);
-       if (StaticReadEvent)
-               free(StaticReadEvent);
-       if (WriteEvent)
-               free(WriteEvent);
-       if (ReadEvent)
-               free(ReadEvent);
+       if (fd_evts[DIR_WR])
+               free(fd_evts[DIR_WR]);
+       if (fd_evts[DIR_RD])
+               free(fd_evts[DIR_RD]);
+       if (tmp_evts[DIR_WR])
+               free(tmp_evts[DIR_WR]);
+       if (tmp_evts[DIR_RD])
+               free(tmp_evts[DIR_RD]);
        p->private = NULL;
        p->pref = 0;
 }
@@ -187,22 +158,22 @@ REGPRM2 static void select_poll(struct poller *p, int wait_time)
 
        readnotnull = 0; writenotnull = 0;
        for (i = 0; i < (maxfd + FD_SETSIZE - 1)/(8*sizeof(int)); i++) {
-               readnotnull |= (*(((int*)ReadEvent)+i) = *(((int*)StaticReadEvent)+i)) != 0;
-               writenotnull |= (*(((int*)WriteEvent)+i) = *(((int*)StaticWriteEvent)+i)) != 0;
+               readnotnull |= (*(((int*)tmp_evts[DIR_RD])+i) = *(((int*)fd_evts[DIR_RD])+i)) != 0;
+               writenotnull |= (*(((int*)tmp_evts[DIR_WR])+i) = *(((int*)fd_evts[DIR_WR])+i)) != 0;
        }
 
        //      /* just a verification code, needs to be removed for performance */
        //      for (i=0; i<maxfd; i++) {
-       //          if (FD_ISSET(i, ReadEvent) != FD_ISSET(i, StaticReadEvent))
+       //          if (FD_ISSET(i, tmp_evts[DIR_RD]) != FD_ISSET(i, fd_evts[DIR_RD]))
        //              abort();
-       //          if (FD_ISSET(i, WriteEvent) != FD_ISSET(i, StaticWriteEvent))
+       //          if (FD_ISSET(i, tmp_evts[DIR_WR]) != FD_ISSET(i, fd_evts[DIR_WR]))
        //              abort();
        //          
        //      }
 
        status = select(maxfd,
-                       readnotnull ? ReadEvent : NULL,
-                       writenotnull ? WriteEvent : NULL,
+                       readnotnull ? tmp_evts[DIR_RD] : NULL,
+                       writenotnull ? tmp_evts[DIR_WR] : NULL,
                        NULL,
                        (wait_time >= 0) ? &delta : NULL);
       
@@ -212,20 +183,20 @@ REGPRM2 static void select_poll(struct poller *p, int wait_time)
                return;
 
        for (fds = 0; (fds << INTBITS) < maxfd; fds++) {
-               if ((((int *)(ReadEvent))[fds] | ((int *)(WriteEvent))[fds]) == 0)
+               if ((((int *)(tmp_evts[DIR_RD]))[fds] | ((int *)(tmp_evts[DIR_WR]))[fds]) == 0)
                        continue;
 
                for (count = 1<<INTBITS, fd = fds << INTBITS; count && fd < maxfd; count--, fd++) {
                        /* if we specify read first, the accepts and zero reads will be
                         * seen first. Moreover, system buffers will be flushed faster.
                         */
-                       if (FD_ISSET(fd, ReadEvent)) {
+                       if (FD_ISSET(fd, tmp_evts[DIR_RD])) {
                                if (fdtab[fd].state == FD_STCLOSE)
                                        continue;
                                fdtab[fd].cb[DIR_RD].f(fd);
                        }
 
-                       if (FD_ISSET(fd, WriteEvent)) {
+                       if (FD_ISSET(fd, tmp_evts[DIR_WR])) {
                                if (fdtab[fd].state == FD_STCLOSE)
                                        continue;
                                fdtab[fd].cb[DIR_WR].f(fd);