From fc3ac62218f0d3dd6cb8a800b3c5de8c4bdf51a0 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Thu, 17 Nov 2016 16:25:19 -0800 Subject: [PATCH] TIMER: Fix coscheduling to avoid a 0 delay interval When the timer subsystem hasn't gotten fully initialized, devices may attempt to coschedule schedule events before the clock has gotten far enough along to be fully initialized. When this happens we now make sure to avoid the potential for a zero delay which will may cause an infinite scheduling loop. --- sim_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sim_timer.c b/sim_timer.c index 18181773..f847289b 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -89,6 +89,9 @@ #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef MAX +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif //#define MS_MIN_GRANULARITY 20 #define MS_MIN_GRANULARITY 1 @@ -2194,7 +2197,7 @@ if (tmr == SIM_INTERNAL_CLK) tmr = SIM_NTIMERS; else { if ((tmr < 0) || (tmr >= SIM_NTIMERS)) - return sim_activate (uptr, ticks * 10000); + return sim_activate (uptr, MAX(1, ticks) * 10000); } if (NULL == sim_clock_unit[tmr]) return sim_activate (uptr, ticks * (rtc_currd[tmr] ? rtc_currd[tmr] : _tick_size ()));