From 1ebfbbaa50fd800e9e806472b7c57e690551e9d0 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 11 May 2021 11:53:15 +0000 Subject: [PATCH] Minor optimization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14366 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/rt/src/chvt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 292f0b84d..46d18f8b5 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -264,13 +264,16 @@ void chVTDoResetI(virtual_timer_t *vtp) { (void) ch_dlist_dequeue(&vtp->dlist); /* Adding delta to the next element, if it is not the last one.*/ - if (is_timer(&vtlp->dlist, vtp->dlist.next)) { - vtp->dlist.next->delta += vtp->dlist.delta; - } + vtp->dlist.next->delta += vtp->dlist.delta; /* Marking timer as not armed.*/ vtp->dlist.next = NULL; + /* Special case when the removed element from the last position in the list, + the value in the header must be restored, just doing it is faster than + checking then doing.*/ + vtlp->dlist.delta = (sysinterval_t)-1; + return; } @@ -416,6 +419,7 @@ void chVTDoTickI(void) { lasttime = chTimeAddX(vtlp->lasttime, dlp->delta); vtlp->lasttime = lasttime; + // TODO, remove this assert, it is triggered also by some valid cases. chDbgAssert((int)chTimeDiffX(vtlp->lasttime, now) >= 0, "back in time"); /* Removing the timer from the list, marking it as not armed.*/ @@ -434,7 +438,7 @@ void chVTDoTickI(void) { vtp->func(vtp, vtp->par); chSysLockFromISR(); - /* Delta between current time after callback and last execution time.*/ + /* Delta between current time after callback execution time.*/ now = chVTGetSystemTimeX(); nowdelta = chTimeDiffX(lasttime, now);