From 18399c1f1267128fef42962738cd1c141fd77118 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Wed, 9 Feb 2011 21:08:20 +0000 Subject: [PATCH] Fix handling rescheduled timers that are already expired. SVN revision: 56876 --- src/timers.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/timers.c b/src/timers.c index d7144ae2..2b9bf505 100644 --- a/src/timers.c +++ b/src/timers.c @@ -210,7 +210,16 @@ TimersRun(unsigned int t_ms) } timer = q_first; - tn = (timer) ? t = timer->at_time - t : 0; + + /* If the next (rescheduled) timer is already expired, set timeout time + * to 1 ms. This avoids starving the fd's and should maintain the intended + * (mean) timer rate. + * The (mean) amount of work done in a timer function should of course not + * exceed the timeout time. */ + if (timer) + tn = (int)(timer->at_time - t) > 0 ? timer->at_time - t : 1; + else + tn = 0; if (EDebug(EDBUG_TYPE_TIMERS)) Eprintf("TimersRun - next in %8u\n", tn);