apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Querna <c...@force-elite.com>
Subject Pollset: Thread Safe & More
Date Thu, 23 Sep 2004 02:57:24 GMT
Attached is a Patch for apr_pollset_*. 
Changes Include:
- Replace HAS_* with USE_* to remove some complex #ifdef stuff.
- Partially thread safe (*)
- Removes the limitation on the number of sockets that you can add to a
pollset (**)

* The patch allows multiple threads to concurrently call _add() or
_remove().  It is still only safe for one thread to call _poll() at a
time. This is only for EPoll and KQueue.

** It will still only return the the maximum number of pollfds you
declared in _create() to any single _poll() call. (pollset->nalloc).
This is only for EPoll and KQueue.

The patch removes the query_set array, and instead uses a set of 3
APR_RINGs to manage the pollfds:
query_ring - pollfds that are in active use. 
dead_ring - pollfds that need to be free`ed after the next _poll()
free_ring - pollfds that we are free to reuse

in _add():
- If there is an extra pollfd in the free_ring, reuse it.
- If not, palloc() one.

in _remove():
- Move the pollfd from the query_ring to the dead_ring

in _poll():
- After polling is complete, move any pollfds inside the dead_ring to
the free_ring, as it is safe to re-use them now.

I would like to use these changes in the 'event' MPM for httpd.

My primary motivations for the pollset changes where:
 - Not acceptable for an _add() to fail because the query_set array was
too small.  
 - Not acceptable to have to do high level locking of the different
pollset functions.  

With these changes, 'Worker' threads can _add a socket directly back
into the Event Threads pollset, without having to wake it the Event
Thread, or preform any extra locking.

I have tested these changed on both 2.6 Linux (EPoll) and Mac OS X
10.3.5 (KQueue).

Currently, the file poll.c has turned into an "#ifdef' hell.  In the
near future, I would like to break out the current poll.c file into
multiple files, one for each major implementation, eg:

If there are no objects to breaking it up into multiple files, I will
take a swing at it this weekend.  

I almost consider the Current Patch to be un-reviewable, because of all
the things I had to change.  If I can break pollset into multiple files,
hopefully, I can make a much more reviewable patch. :)

A word of thanks to Rici Lake for helping me debug these changes via

As always, comments are very welcome.

-Paul Querna

View raw message