From 42bb47d961aa5c8587ad55190648cd4e42ef1bad Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 7 Mar 2020 07:05:46 -0800 Subject: [PATCH] TIMER: Be sure to empty the event queue at timer initialization If a reset_all_p() happens before the timing subsystem is initialized, events can be queued with unreasonable timing measurements. --- sim_timer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sim_timer.c b/sim_timer.c index 4377b811..61a5cae1 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -1124,12 +1124,18 @@ int tmr; uint32 clock_start, clock_last, clock_now; sim_debug (DBG_TRC, &sim_timer_dev, "sim_timer_init()\n"); +/* Clear the event queue before initializing the timer subsystem */ +while (sim_clock_queue != QUEUE_LIST_END) + sim_cancel (sim_clock_queue); for (tmr=0; tmr<=SIM_NTIMERS; tmr++) { RTC *rtc = &rtcs[tmr]; rtc->timer_unit = &sim_timer_units[tmr]; rtc->timer_unit->action = &sim_timer_tick_svc; rtc->timer_unit->flags = UNIT_DIS | UNIT_IDLE; + if (rtc->clock_cosched_queue) + while (rtc->clock_cosched_queue != QUEUE_LIST_END) + sim_cancel (rtc->clock_cosched_queue); rtc->clock_cosched_queue = QUEUE_LIST_END; } sim_stop_unit.action = &sim_timer_stop_svc;