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) {
if (t->timer == timer && t->param == param) {
return 1 + (t->when - avr->cycle);
}
- t->next = pool->timer_free;
+ t = t->next;
}
return 0;
}
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);
}
// 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;
}