[PATCH] event-loop: Only read one epoll event per loop dispatch.

Bill Spitzak spitzak at gmail.com
Mon Mar 19 13:44:40 PDT 2012



Jonas Ådahl wrote:
> On Mon, Mar 19, 2012 at 7:10 PM, Bill Spitzak <spitzak at gmail.com> wrote:
>> Jonas Ådahl wrote:
>>
>>> That would not work because ep[i].data.ptr will already be loaded with
>>> the source pointer pointing to deallocated memory. It doesn't matter
>>> if that particular source is free:ed and removed from the epoll state
>>> since it has already been triggered to dispatch. Another approach
>>> would be to flag an event source for removal if it already has been
>>> queued up then have the event_loop_dispatch function remove it after
>>> or instead of handling it.
>>
>> How about having the data point at another object that points at the source.
>> This object is not deleted until after the epoll is used, but when the
>> source is deleted it is set to zero so this is detectable.
>>
> 
> An event source container acting as a proxy between epoll and the
> event source? When receiving an event, instead of marking the event
> source directly, one could mark the container as queued. When an event
> source is removed from epoll then one can check if it has been queued
> by accessing the container via the event source, and in that case mark
> it for destruction, or free it directly in case it wasn't. Is this
> what you mean? It sounds quite reasonable.

No I meant a simpler version. There is no "mark for destruction", the 
object is destroyed immediately. But a side-effect of destruction is 
that the pointer from the epoll structure pointing at it is set to zero. 
Epoll handling is something like this:

	source** p = (source**)(epoll[n].data);
	if (*p) ((*p)->stuff());

The destruction of a source clears *p. p itself is not destroyed until 
the epoll object is.

Assuming the set of source objects is somewhat stable (ie you will call 
epoll many times verses the number of times the source list chagnes) I 
would keep all the p pointers in static memory, perhaps in a table. The 
empty entries are reclaimed at points where you know there is no epoll 
using them.


More information about the wayland-devel mailing list