Re: [AD] ALLEGRO_TIMEOUT

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


On 2010-11-06, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> On 6 Nov 2010, at 1:56 , Thomas Fjellstrom wrote:
> > Nope, its used with the al_wait_for_event_until. And might be used elsewhere. 
> 
> In the public API it isn't used anywhere else that I can see from the documentation.
> I've documented what it's used for, but I do have to wonder whether it makes sense to have a dedicated type that has a constructor function and one use function.
> Wouldn't it make more sense to have
> 
> bool al_wait_for_event_until(ALLEGRO_EVENT_QUEUE *queue,
>    ALLEGRO_EVENT *ret_event, double seconds)

There already exists al_wait_for_event_timed.

al_wait_cond_timed also uses ALLEGRO_TIMEOUT.
Oops, it uses the word "timed" instead of "until".  I'll change it.

> rather than the pair of
> 
> void al_init_timeout(ALLEGRO_TIMEOUT *timeout, double seconds)
> bool al_wait_for_event_until(ALLEGRO_EVENT_QUEUE *queue,
>    ALLEGRO_EVENT *ret_event, ALLEGRO_TIMEOUT *timeout)
> 
> ?

al_wait_for_event_until is potentially more precise in a loop:

    al_init_timeout(&timeout, MAX_DELAY);
    while (al_wait_for_event_until(queue, &event, &timeout)) {
	process_event(&event);
    }

The equivalent with al_wait_for_event_timed would be:

    end = al_get_time() + MAX_DELAY;
    while (al_wait_for_event_timed(queue, &event, end - al_get_time())) {
	process_event(&event);
    }

Now, the process may be preempted before al_wait_for_event_timed has a
chance to retrieve the current time.  When the process resumes, the
current time will have changed, so the delay will be longer than it
should have been.  There also is the overhead of recomputing the native
timeout structure.

There is still the problem of preemption in al_init_timeout.
If needs be, we could add a function in the future:

    al_init_timeout_abs(ALLEGRO_TIMEOUT *timeout, float abstime);

Peter




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