Re: [AD] rest and yield_timeslice

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


Actually, currently they call nothing. They do a busy wait that calls yield_timeslice. Previously however, they used select. My and Elias talked this over the other night/morning and we came to the conclusion that nanosleep would be a better function to rest with. It's POSIX-compliant unlike usleep, it's more flexible, and under certain situations can be more accurate than other rest functions.

Ok.

Okay, so it's something like this:
sleep_program();
wait_time();
restore_program();

As I said before, I believe something like this is completely ineffient for games. Since rescheduling can make your program wait up to 10ms, I think resting 0ms should be 0ms instead of 0-10ms. 1-10 = ~10, 11-20 = ~20, etc.

True, the rescheduling will make it loose some milliseconds. But we stated nowhere rest() is meant to be used for accurate timing. When you need accurate timing, you'd better stick with Allegro timers. rest() is just a convenience function AFAIK, whose behaviour could be modified to suit our current needs of a sleeping/yielding function.

But the thing is, I don't think it should've been put in the queue if you know you're going to immediately restore it. Unix provides sched_yield() to yield the timeslice instead of relying on resting for 0ms, and Allegro should follow suit. However with Allegro, we need as platform independant behavior as possible, and relying on the OS's sleep function isn't a good idea since it can vary from 0ms to 10ms to up to 30ms(!), so it should return immediately. Most applications can take the hit and not really suffer.. however for games it means the difference between 30fps, 100fps, or more. Resting up to 30ms when they ask for 0ms is a very bad idea, IMO.

Again, rest() is not meant to be used in an inner game loop. Timers are meant for this.
And we could do this:

void rest(int x)
{
   return timer_driver->rest(x);
}

void unix_timer_rest(x)
{
   if (x)
      nanosleep(x);
   else
      sched_yield();
}

And do similar things for other platforms.

So why use another function (yield_timeslice) when you can reuse this one?

Because the two serve two different functions. One rests when you have nothing to do (and when you rest for <= 0ms, you obviously have something to do), the other plays nice and shares the CPU with other programs.

But then you'd be fool to call rest(0) since it does nothing. I was suggesting to merge the functions because rest(0) has no real meaning currently, and because I wanted to reduce slightly API clutter...

--
Angelo Mottola
a.mottola@xxxxxxxxxx
http://www.ecplusplus.com





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