Re: [AD] user-defined events

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2008-10-16, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> 
> However, I'm not very happy about it, that cleanup loop is kinda ugly,
> and much worse, I'm not 100% sure the example is correct (when applied
> to an actual game with 100ds of events created everywhere).
> 
> Would it be acceptable to add a callback to ALLEGRO_USER_EVENT which is
> called whenever an event is to be destroyed? Or if needed, also another
> callback whenever it is duplicated (I assume the only way for this to
> happen is when the event source is connected to two queues - but as long
> as we support that, we must expect users two use it). I think I already
> suggested it earlier, but the callbacks would look something like:
> 
> void (*destroy_user_event)(ALLEGRO_EVENT *event);
> void (*copy_user_event)(ALLEGRO_EVENT *event);
> 
> Then my version of ex_user_events simply would fill in the callbacks and
> the burden would be shifted to Allegro to make sure they are called at
> the right time.

When is an event supposed to be destroyed?  al_wait_for_event() returns a
copy of the event, probably on the user's stack.  Allegro doesn't know
when that copy is no longer needed, so the user needs to explicitly call
an unref function.

Implementing reference counting for user events wouldn't actually be
hard, but I'm still unsure.  If you use atomic instructions then you
would at least avoid having an extra mutex per event.  Maybe do it as an
exercise and see?

Or use a conservative garbage collector..

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/