From f32d1e094163de8cba88ddef023e588a4b44a76f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 13 Sep 2013 13:15:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6302 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/nil/src/nil.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'os/nil') diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c index 7f1ee3516..5d9a660f7 100644 --- a/os/nil/src/nil.c +++ b/os/nil/src/nil.c @@ -337,29 +337,32 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) { #if NIL_CFG_ST_TIMEDELTA > 0 if (timeout != TIME_INFINITE) { - systime_t time = chVTGetSystemTimeX() + timeout; + systime_t abstime; /* TIMEDELTA makes sure to have enough time to reprogram the timer before the free-running timer counter reaches the selected timeout.*/ if (timeout < NIL_CFG_ST_TIMEDELTA) timeout = NIL_CFG_ST_TIMEDELTA; + /* Absolute time of the timeout event.*/ + abstime = chVTGetSystemTimeX() + timeout; + if (nil.lasttime == nil.nexttime) { /* Special case, first thread asking for a timeout.*/ - port_timer_start_alarm(time); - nil.nexttime = time; + port_timer_start_alarm(abstime); + nil.nexttime = abstime; } else { /* Special case, there are already other threads with a timeout activated, evaluating the order.*/ - if (chVTIsTimeWithinX(time, nil.lasttime, nil.nexttime)) { - port_timer_set_alarm(time); - nil.nexttime = time; + if (chVTIsTimeWithinX(abstime, nil.lasttime, nil.nexttime)) { + port_timer_set_alarm(abstime); + nil.nexttime = abstime; } } /* Timeout settings.*/ - otp->timeout = time - nil.lasttime; + otp->timeout = abstime - nil.lasttime; } #else -- cgit v1.2.3