aboutsummaryrefslogtreecommitdiffstats
path: root/os/nil
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-12-13 09:38:26 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-12-13 09:38:26 +0000
commit27c8d2c34e616b2bbf67193d0bbd2eaf0f41a128 (patch)
tree9a95c0a154ecad03cc4abdd1db17a0d6f74a99bd /os/nil
parent39a0718d2cd9a1766ff570e98c4854667159b6a2 (diff)
downloadChibiOS-27c8d2c34e616b2bbf67193d0bbd2eaf0f41a128.tar.gz
ChibiOS-27c8d2c34e616b2bbf67193d0bbd2eaf0f41a128.tar.bz2
ChibiOS-27c8d2c34e616b2bbf67193d0bbd2eaf0f41a128.zip
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
Diffstat (limited to 'os/nil')
-rw-r--r--os/nil/src/ch.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/os/nil/src/ch.c b/os/nil/src/ch.c
index 562259913..7fdf6812f 100644
--- a/os/nil/src/ch.c
+++ b/os/nil/src/ch.c
@@ -326,7 +326,7 @@ void chSysTimerHandlerI(void) {
chDbgAssert(!NIL_THD_IS_READY(tp), "is ready");
- /* Did the timer reach zero?*/
+ /* Did the timer reach zero?*/
if (--tp->timeout == (systime_t)0) {
/* Timeout on semaphores requires a special handling because the
semaphore counter must be incremented.*/
@@ -354,14 +354,19 @@ void chSysTimerHandlerI(void) {
chDbgAssert(nil.nexttime == port_timer_get_alarm(), "time mismatch");
do {
+ systime_t timeout = tp->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(tp->timeout >= (nil.nexttime - nil.lasttime), "skipped one");
+ chDbgAssert(timeout >= (nil.nexttime - nil.lasttime), "skipped one");
+
+ /* The volatile field is updated once, here.*/
+ timeout -= nil.nexttime - nil.lasttime;
+ tp->timeout = timeout;
- tp->timeout -= nil.nexttime - nil.lasttime;
- if (tp->timeout == (systime_t)0) {
+ if (timeout == (systime_t)0) {
#if CH_CFG_USE_SEMAPHORES == TRUE
/* Timeout on semaphores requires a special handling because the
semaphore counter must be incremented.*/
@@ -379,17 +384,19 @@ void chSysTimerHandlerI(void) {
(void) chSchReadyI(tp, MSG_TIMEOUT);
}
else {
- if (tp->timeout <= (systime_t)(next - (systime_t)1)) {
- next = tp->timeout;
+ if (timeout <= (systime_t)(next - (systime_t)1)) {
+ next = timeout;
}
}
}
+
/* Lock released in order to give a preemption chance on those
architectures supporting IRQ preemption.*/
chSysUnlockFromISR();
tp++;
chSysLockFromISR();
} while (tp < &nil.threads[CH_CFG_NUM_THREADS]);
+
nil.lasttime = nil.nexttime;
if (next > (systime_t)0) {
nil.nexttime += next;