On Fri, Nov 27, 2026 at 7:28 PM Ruediger Pluem via dev <[email protected]> wrote: > > On 11/27/26 6:21 PM, ylavic.apache.org via commits wrote: > > Author: ylavic > > Date: Fri Nov 27 17:21:44 2026 > > New Revision: 1940824 > > > > Log: > > apr_pollset: port: don't recycle event elements a concurrent poller holds. > > > > impl_pollset_poll() moves the dead ring (elements removed while possibly > > returned by a port_getn()) to the free ring at the end of every poll. With > > several threads polling an APR_POLLSET_THREADSAFE pollset, an element > > returned to one poller's port_getn() and removed meanwhile can be recycled > > by another poller finishing first, and reused by an add for another > > descriptor before the first poller handles it (reporting the wrong > > descriptor). > > > > Count the pollers from before their port_getn() until their events are > > processed (under the ring lock), and recycle the dead ring only when the > > last one is done. > > > > * poll/unix/port.c: > > (struct apr_pollset_private_t): Add polling, document waiting more > > precisely. > > (impl_pollset_create): Initialize polling. > > (poll_begin): New, associate the add ring with the port and count the > > poller. > > (poll_fired): New, move a returned element to the add ring. > > (poll_end): New, recycle the dead ring once no poller is left. > > (impl_pollset_poll): Use them. > > > > Modified: > > apr/apr/trunk/poll/unix/port.c > > > > Modified: apr/apr/trunk/poll/unix/port.c > > ============================================================================== > > --- apr/apr/trunk/poll/unix/port.c Fri Nov 27 16:54:00 2026 > > (r1940823) > > +++ apr/apr/trunk/poll/unix/port.c Fri Nov 27 17:21:44 2026 > > (r1940824) > > > while (!APR_RING_EMPTY(&(pollset->p->add_ring), pfd_elem_t, link)) { > > @@ -390,10 +388,62 @@ static apr_status_t impl_pollset_poll(ap > > APR_RING_INSERT_TAIL(&(pollset->p->query_ring), ep, pfd_elem_t, > > link); > > } > > > > - pollset_unlock_rings(); > > - > > if (rv != APR_SUCCESS) { > > apr_atomic_dec32(&pollset->p->waiting); > > + } > > + else { > > + /* counted before port_getn(): what it returns must not be recycled > > + * by another poller's poll_end() until this one's poll_end() > > + */ > > + pollset->p->polling++; > > Why doesn't this need to be done by apr_atomic_inc32?
Here and for the other cases too, ->polling lives entirely under the lock so it needs not be atomic. As opposed to ->waiting which is atomic everywhere (including under the lock) because it's decremented without the lock from impl_pollset_poll(), to shorten the window where impl_pollset_add() has to call port_associate() (see the comment there). Cheers; Yann.
