From 9f7674d506c5fe69d0b938908bbca6919b7bc0dd Mon Sep 17 00:00:00 2001 From: bernie Date: Thu, 14 Oct 2004 23:14:05 +0000 Subject: [PATCH] Fix longstanding problem with wrap-arounds. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@236 38d2e660-2303-0410-9eaa-f027e97ec537 --- drv/timer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drv/timer.c b/drv/timer.c index 92152bc1..101a468d 100755 --- a/drv/timer.c +++ b/drv/timer.c @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.18 2004/10/14 23:14:05 bernie + *#* Fix longstanding problem with wrap-arounds. + *#* *#* Revision 1.17 2004/10/03 18:52:08 bernie *#* Move \brief on top in header to please Doxygen. *#* @@ -102,14 +105,18 @@ void timer_add(Timer *timer) /* Calculate expiration time for this timer */ timer->tick = _clock + timer->delay; - /* Search for the first node whose expiration time is + /* + * Search for the first node whose expiration time is * greater than the timer we want to add. */ node = (Timer *)timers_queue.head; while (node->link.succ) { - /* Stop just after the insertion point */ - if (node->tick > timer->tick) + /* + * Stop just after the insertion point. + * (this fancy compare takes care of wrap-arounds). + */ + if (node->tick - timer->tick > 0) break; /* Go to next node */ -- 2.25.1