Timer handling code size improvement in tickless mode.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9961 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2016-12-13 09:38:26 +00:00
parent 39a0718d2c
commit 27c8d2c34e
1 changed files with 14 additions and 7 deletions

View File

@ -326,7 +326,7 @@ void chSysTimerHandlerI(void) {
chDbgAssert(!NIL_THD_IS_READY(tp), "is ready"); chDbgAssert(!NIL_THD_IS_READY(tp), "is ready");
/* Did the timer reach zero?*/ /* Did the timer reach zero?*/
if (--tp->timeout == (systime_t)0) { if (--tp->timeout == (systime_t)0) {
/* Timeout on semaphores requires a special handling because the /* Timeout on semaphores requires a special handling because the
semaphore counter must be incremented.*/ semaphore counter must be incremented.*/
@ -354,14 +354,19 @@ void chSysTimerHandlerI(void) {
chDbgAssert(nil.nexttime == port_timer_get_alarm(), "time mismatch"); chDbgAssert(nil.nexttime == port_timer_get_alarm(), "time mismatch");
do { do {
systime_t timeout = tp->timeout;
/* Is the thread in a wait state with timeout?.*/ /* Is the thread in a wait state with timeout?.*/
if (tp->timeout > (systime_t)0) { if (timeout > (systime_t)0) {
chDbgAssert(!NIL_THD_IS_READY(tp), "is ready"); chDbgAssert(!NIL_THD_IS_READY(tp), "is ready");
chDbgAssert(tp->timeout >= (nil.nexttime - nil.lasttime), "skipped one"); chDbgAssert(timeout >= (nil.nexttime - nil.lasttime), "skipped one");
tp->timeout -= nil.nexttime - nil.lasttime; /* The volatile field is updated once, here.*/
if (tp->timeout == (systime_t)0) { timeout -= nil.nexttime - nil.lasttime;
tp->timeout = timeout;
if (timeout == (systime_t)0) {
#if CH_CFG_USE_SEMAPHORES == TRUE #if CH_CFG_USE_SEMAPHORES == TRUE
/* Timeout on semaphores requires a special handling because the /* Timeout on semaphores requires a special handling because the
semaphore counter must be incremented.*/ semaphore counter must be incremented.*/
@ -379,17 +384,19 @@ void chSysTimerHandlerI(void) {
(void) chSchReadyI(tp, MSG_TIMEOUT); (void) chSchReadyI(tp, MSG_TIMEOUT);
} }
else { else {
if (tp->timeout <= (systime_t)(next - (systime_t)1)) { if (timeout <= (systime_t)(next - (systime_t)1)) {
next = tp->timeout; next = timeout;
} }
} }
} }
/* Lock released in order to give a preemption chance on those /* Lock released in order to give a preemption chance on those
architectures supporting IRQ preemption.*/ architectures supporting IRQ preemption.*/
chSysUnlockFromISR(); chSysUnlockFromISR();
tp++; tp++;
chSysLockFromISR(); chSysLockFromISR();
} while (tp < &nil.threads[CH_CFG_NUM_THREADS]); } while (tp < &nil.threads[CH_CFG_NUM_THREADS]);
nil.lasttime = nil.nexttime; nil.lasttime = nil.nexttime;
if (next > (systime_t)0) { if (next > (systime_t)0) {
nil.nexttime += next; nil.nexttime += next;