timer: add function timer_delay()

This commit is contained in:
Max Kellermann 2010-11-05 09:39:50 +01:00
parent ec48b5ea3a
commit ad430c6617
2 changed files with 19 additions and 0 deletions

View File

@ -71,6 +71,19 @@ void timer_add(Timer *timer, int size)
timer->time += ((uint64_t)size * 1000000) / timer->rate;
}
unsigned
timer_delay(const Timer *timer)
{
int64_t delay = timer->time - now();
if (delay < 0)
return 0;
if (delay > 1000 * 1000 * 1000)
return 1000 * 1000;
return delay / 1000;
}
void timer_sync(Timer *timer)
{
int64_t sleep_duration;

View File

@ -40,6 +40,12 @@ void timer_reset(Timer *timer);
void timer_add(Timer *timer, int size);
/**
* Returns the number of milliseconds to sleep to get back to sync.
*/
unsigned
timer_delay(const Timer *timer);
void timer_sync(Timer *timer);
#endif