]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: polling: create function fd_compute_new_polled_status()
authorWilly Tarreau <w@1wt.eu>
Sat, 25 Jan 2014 09:32:56 +0000 (10:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 25 Jan 2014 23:42:32 +0000 (00:42 +0100)
This function is used to compute the new polling state based on
the previous state. All pollers have to do this in their update
loop, so better centralize the logic for it.

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

index f74fbcbb526ae9f0e58bb5240947cdd17d2b0e72..605dc215ff2758e8722a12f91ad307e9e2a07e5a 100644 (file)
@@ -135,6 +135,28 @@ static inline void fd_release_cache_entry(int fd)
        }
 }
 
+/* Computes the new polled status based on the active and ready statuses, for
+ * each direction. This is meant to be used by pollers while processing updates.
+ */
+static inline int fd_compute_new_polled_status(int state)
+{
+       if (state & FD_EV_ACTIVE_R) {
+               if (!(state & FD_EV_READY_R))
+                       state |= FD_EV_POLLED_R;
+       }
+       else
+               state &= ~FD_EV_POLLED_R;
+
+       if (state & FD_EV_ACTIVE_W) {
+               if (!(state & FD_EV_READY_W))
+                       state |= FD_EV_POLLED_W;
+       }
+       else
+               state &= ~FD_EV_POLLED_W;
+
+       return state;
+}
+
 /* Automatically allocates or releases a cache entry for fd <fd> depending on
  * its new state. This is meant to be used by pollers while processing updates.
  */
index b90d9c153e2a92c2b1a0dfefcf1e3595c04ffee4..2849ec6c1712c146da178fb48a93b4b32dd51c7a 100644 (file)
@@ -59,27 +59,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = eo = fdtab[fd].state;
-
                fdtab[fd].updated = 0;
                fdtab[fd].new = 0;
 
                if (!fdtab[fd].owner)
                        continue;
 
-               if (en & FD_EV_ACTIVE_R) {
-                       if (!(en & FD_EV_READY_R))
-                               en |= FD_EV_POLLED_R;
-               }
-               else
-                       en &= ~FD_EV_POLLED_R;
-
-               if (en & FD_EV_ACTIVE_W) {
-                       if (!(en & FD_EV_READY_W))
-                               en |= FD_EV_POLLED_W;
-               }
-               else
-                       en &= ~FD_EV_POLLED_W;
+               eo = fdtab[fd].state;
+               en = fd_compute_new_polled_status(eo);
 
                if ((eo ^ en) & FD_EV_POLLED_RW) {
                        /* poll status changed */
index 0473adc349a8a56a0edb561bbd281cb53ff5570f..06ccaee292ab17a10e9427b91e64ae94be5f046a 100644 (file)
@@ -47,28 +47,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = eo = fdtab[fd].state;
-
                fdtab[fd].updated = 0;
                fdtab[fd].new = 0;
 
                if (!fdtab[fd].owner)
                        continue;
 
-               if (en & FD_EV_ACTIVE_R) {
-                       if (!(en & FD_EV_READY_R))
-                               en |= FD_EV_POLLED_R;
-               }
-               else
-                       en &= ~FD_EV_POLLED_R;
-
-               if (en & FD_EV_ACTIVE_W) {
-                       if (!(en & FD_EV_READY_W))
-                               en |= FD_EV_POLLED_W;
-               }
-               else
-                       en &= ~FD_EV_POLLED_W;
-
+               eo = fdtab[fd].state;
+               en = fd_compute_new_polled_status(eo);
 
                if ((eo ^ en) & FD_EV_POLLED_RW) {
                        /* poll status changed */
index 84ba486b8914bff9a3d8acc783fa403080349eb0..2f6e56d3c43d4a6abe9c30982f0864f59e3b7b7f 100644 (file)
@@ -70,27 +70,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = eo = fdtab[fd].state;
-
                fdtab[fd].updated = 0;
                fdtab[fd].new = 0;
 
                if (!fdtab[fd].owner)
                        continue;
 
-               if (en & FD_EV_ACTIVE_R) {
-                       if (!(en & FD_EV_READY_R))
-                               en |= FD_EV_POLLED_R;
-               }
-               else
-                       en &= ~FD_EV_POLLED_R;
-
-               if (en & FD_EV_ACTIVE_W) {
-                       if (!(en & FD_EV_READY_W))
-                               en |= FD_EV_POLLED_W;
-               }
-               else
-                       en &= ~FD_EV_POLLED_W;
+               eo = fdtab[fd].state;
+               en = fd_compute_new_polled_status(eo);
 
                if ((eo ^ en) & FD_EV_POLLED_RW) {
                        /* poll status changed, update the lists */
index 87ca348a680b41bf6bcc2d3cfe42d4ce30937090..5a76d44c074af54b93f791ab4693e3d67d291e05 100644 (file)
@@ -53,27 +53,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = eo = fdtab[fd].state;
-
                fdtab[fd].updated = 0;
                fdtab[fd].new = 0;
 
                if (!fdtab[fd].owner)
                        continue;
 
-               if (en & FD_EV_ACTIVE_R) {
-                       if (!(en & FD_EV_READY_R))
-                               en |= FD_EV_POLLED_R;
-               }
-               else
-                       en &= ~FD_EV_POLLED_R;
-
-               if (en & FD_EV_ACTIVE_W) {
-                       if (!(en & FD_EV_READY_W))
-                               en |= FD_EV_POLLED_W;
-               }
-               else
-                       en &= ~FD_EV_POLLED_W;
+               eo = fdtab[fd].state;
+               en = fd_compute_new_polled_status(eo);
 
                if ((eo ^ en) & FD_EV_POLLED_RW) {
                        /* poll status changed, update the lists */