diff options
author | Daniel Stone <daniel@fooishbar.org> | 2006-10-29 03:40:57 +0300 |
---|---|---|
committer | Daniel Stone <daniels@endtroducing.fooishbar.org> | 2006-10-29 03:40:57 +0300 |
commit | 51a06b3c44509c72279b5cfcf2b52b9a35c461b0 (patch) | |
tree | 8b0a5c4c3334d5453194779fac51d32afb4be79c /os | |
parent | 196c5836f463c28f633bbba847f59acd5935359d (diff) |
WaitForSomething: only rewind when delta is more than 250ms
Only rewind time when we're more than (original delta + 250ms) away from
executing the timer.
When we're walking the timer list, use a goto to iterate all of them from
the start again, since timers may drop out of the list.
Don't bother trying to be smart in TimerSet, we'll pick it up in
WaitForSomething anyway.
Diffstat (limited to 'os')
-rw-r--r-- | os/WaitFor.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/os/WaitFor.c b/os/WaitFor.c index 896fdf15d..6109e3477 100644 --- a/os/WaitFor.c +++ b/os/WaitFor.c @@ -202,11 +202,12 @@ WaitForSomething(int *pClientsReady) { now = GetTimeInMillis(); timeout = timers->expires - now; - /* time has rewound. reset the timers. */ - if (timeout > timers->delta) { + if (timeout > 0 && timeout > timers->delta + 250) { + /* time has rewound. reset the timers. */ CheckAllTimers(now); timeout = timers->expires - now; } + if (timeout < 0) timeout = 0; waittime.tv_sec = timeout / MILLI_PER_SECOND; @@ -434,17 +435,18 @@ ANYSET(FdMask *src) #endif /* If time has rewound, re-run every affected timer. - * TimerForce will change timer->next, but it will _generally_ only - * promote timers in the list, meaning that we should still be - * walking every timer. */ + * Timers might drop out of the list, so we have to restart every time. */ static void CheckAllTimers(CARD32 now) { OsTimerPtr timer; +start: for (timer = timers; timer; timer = timer->next) { - if (timer->expires - now > timer->delta) + if (timer->expires - now > timer->delta + 250) { TimerForce(timer); + goto start; + } } } @@ -507,10 +509,8 @@ TimerSet(OsTimerPtr timer, int flags, CARD32 millis, } for (prev = &timers; *prev && (int) ((*prev)->expires - millis) <= 0; - prev = &(*prev)->next) { - if ((*prev)->expires - now > (*prev)->delta) - CheckAllTimers(now); - } + prev = &(*prev)->next) + ; timer->next = *prev; *prev = timer; return timer; |