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

Jonas Ådahl jadahl at gmail.com
Tue Mar 20 01:07:04 PDT 2012


On Mon, Mar 19, 2012 at 9:44 PM, Bill Spitzak <spitzak at gmail.com> wrote:
>
>
> 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.

How would *p be cleared? When epoll_wait has returned all the
epoll[n].ptr has already been set, and during a dispatch a user may
remove it from epoll from a context where p is not known.

Jonas


More information about the wayland-devel mailing list