MINOR: polling: create function fd_compute_new_polled_status()

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.
This commit is contained in:
Willy Tarreau 2014-01-25 10:32:56 +01:00
parent e852545594
commit 25002d206b
5 changed files with 30 additions and 61 deletions

View 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 /* 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. * its new state. This is meant to be used by pollers while processing updates.
*/ */

View File

@ -59,27 +59,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
/* first, scan the update list to find changes */ /* first, scan the update list to find changes */
for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) { for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
fd = fd_updt[updt_idx]; fd = fd_updt[updt_idx];
en = eo = fdtab[fd].state;
fdtab[fd].updated = 0; fdtab[fd].updated = 0;
fdtab[fd].new = 0; fdtab[fd].new = 0;
if (!fdtab[fd].owner) if (!fdtab[fd].owner)
continue; continue;
if (en & FD_EV_ACTIVE_R) { eo = fdtab[fd].state;
if (!(en & FD_EV_READY_R)) en = fd_compute_new_polled_status(eo);
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;
if ((eo ^ en) & FD_EV_POLLED_RW) { if ((eo ^ en) & FD_EV_POLLED_RW) {
/* poll status changed */ /* poll status changed */

View File

@ -47,28 +47,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
/* first, scan the update list to find changes */ /* first, scan the update list to find changes */
for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) { for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
fd = fd_updt[updt_idx]; fd = fd_updt[updt_idx];
en = eo = fdtab[fd].state;
fdtab[fd].updated = 0; fdtab[fd].updated = 0;
fdtab[fd].new = 0; fdtab[fd].new = 0;
if (!fdtab[fd].owner) if (!fdtab[fd].owner)
continue; continue;
if (en & FD_EV_ACTIVE_R) { eo = fdtab[fd].state;
if (!(en & FD_EV_READY_R)) en = fd_compute_new_polled_status(eo);
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;
if ((eo ^ en) & FD_EV_POLLED_RW) { if ((eo ^ en) & FD_EV_POLLED_RW) {
/* poll status changed */ /* poll status changed */

View File

@ -70,27 +70,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
/* first, scan the update list to find changes */ /* first, scan the update list to find changes */
for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) { for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
fd = fd_updt[updt_idx]; fd = fd_updt[updt_idx];
en = eo = fdtab[fd].state;
fdtab[fd].updated = 0; fdtab[fd].updated = 0;
fdtab[fd].new = 0; fdtab[fd].new = 0;
if (!fdtab[fd].owner) if (!fdtab[fd].owner)
continue; continue;
if (en & FD_EV_ACTIVE_R) { eo = fdtab[fd].state;
if (!(en & FD_EV_READY_R)) en = fd_compute_new_polled_status(eo);
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;
if ((eo ^ en) & FD_EV_POLLED_RW) { if ((eo ^ en) & FD_EV_POLLED_RW) {
/* poll status changed, update the lists */ /* poll status changed, update the lists */

View File

@ -53,27 +53,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
/* first, scan the update list to find changes */ /* first, scan the update list to find changes */
for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) { for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
fd = fd_updt[updt_idx]; fd = fd_updt[updt_idx];
en = eo = fdtab[fd].state;
fdtab[fd].updated = 0; fdtab[fd].updated = 0;
fdtab[fd].new = 0; fdtab[fd].new = 0;
if (!fdtab[fd].owner) if (!fdtab[fd].owner)
continue; continue;
if (en & FD_EV_ACTIVE_R) { eo = fdtab[fd].state;
if (!(en & FD_EV_READY_R)) en = fd_compute_new_polled_status(eo);
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;
if ((eo ^ en) & FD_EV_POLLED_RW) { if ((eo ^ en) & FD_EV_POLLED_RW) {
/* poll status changed, update the lists */ /* poll status changed, update the lists */