From 6208dc71fcdd544b58f19f0d694da426d3fef869 Mon Sep 17 00:00:00 2001 From: 0x1abin <0x1abin@gmail.com> Date: Fri, 20 Aug 2021 10:55:22 +0800 Subject: [PATCH] Optimization timeout removed. --- MultiTimer.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/MultiTimer.c b/MultiTimer.c index 11ddafe..394372d 100644 --- a/MultiTimer.c +++ b/MultiTimer.c @@ -101,17 +101,22 @@ int MultiTimerStop(MultiTimer* timer) */ void MultiTimerYield(void) { - MultiTimer* target = timerList; - for (; target; target = target->next) { - if (target->deadline > platformTicksFunction()) { + MultiTimer** nextTimer = &timerList; + + for (; *nextTimer; nextTimer = &(*nextTimer)->next) { + MultiTimer* entry = *nextTimer; + /* Sorted list, just process with the front part. */ + if (entry->deadline > platformTicksFunction()) { return; } - MultiTimerStop(target); - if (target->period) { - MultiTimerStart(target, target->period); + /* remove expired timer from list */ + *nextTimer = entry->next; + + if (entry->period) { + MultiTimerStart(entry, entry->period); } - if (target->callback) { - target->callback(target, target->userData); + if (entry->callback) { + entry->callback(entry, entry->userData); } } }