From: Michel Pollet Date: Sat, 1 Mar 2014 13:46:34 +0000 (+0000) Subject: timers: Real fix X-Git-Tag: v1.2~29 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=e6cd1e0ff5d62d247078083312a6e3551a8078c6;p=sx%2Fsimavr.git timers: Real fix There were a couple of logic error in the previous commit, fixed, hopefully. --- diff --git a/simavr/sim/sim_cycle_timers.c b/simavr/sim/sim_cycle_timers.c index 2b88393..6ca0462 100644 --- a/simavr/sim/sim_cycle_timers.c +++ b/simavr/sim/sim_cycle_timers.c @@ -73,7 +73,7 @@ avr_cycle_timer_insert( t->timer = timer; t->param = param; t->when = when; - + // find its place in the list avr_cycle_timer_slot_p loop = pool->timer, last = NULL; while (loop) { @@ -153,7 +153,7 @@ avr_cycle_timer_status( if (t->timer == timer && t->param == param) { return 1 + (t->when - avr->cycle); } - t->next = pool->timer_free; + t = t->next; } return 0; } @@ -172,15 +172,15 @@ avr_cycle_timer_process( if (!pool->timer) return (avr_cycle_count_t)1000; - avr_cycle_timer_slot_p t = pool->timer, last = NULL; - while (t) { - avr_cycle_timer_slot_p next = t->next; + do { + avr_cycle_timer_slot_p t = pool->timer; if (t->when > avr->cycle) return t->when - avr->cycle; // detach from active timers - DETACH(pool->timer, last, t); - avr_cycle_count_t when = 0; + pool->timer = t->next; + t->next = NULL; + avr_cycle_count_t when = t->when; do { when = t->timer(avr, when, t->param); } while (when && when <= avr->cycle); @@ -189,9 +189,7 @@ avr_cycle_timer_process( } // requeue this one into the free ones QUEUE(pool->timer_free, t); - last = t; - t = next; - }; + } while (pool->timer); return (avr_cycle_count_t)1000; }