diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-27 06:17:02 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-27 06:17:02 -0600 |
commit | a9137270348022c765557cbe8c506a573304ad57 (patch) | |
tree | 74dd4a1cae48b332b0315570ab4bb03671967f94 /nuttx/sched/wqueue | |
parent | 01ac044d75b9a927f51dc499697b19309761139e (diff) | |
download | px4-nuttx-a9137270348022c765557cbe8c506a573304ad57.tar.gz px4-nuttx-a9137270348022c765557cbe8c506a573304ad57.tar.bz2 px4-nuttx-a9137270348022c765557cbe8c506a573304ad57.zip |
Fix backward calculation in the work queue timing. From Liio Chen via the PX4 repository
Diffstat (limited to 'nuttx/sched/wqueue')
-rw-r--r-- | nuttx/sched/wqueue/kwork_process.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/nuttx/sched/wqueue/kwork_process.c b/nuttx/sched/wqueue/kwork_process.c index 87ed7900d..6333a6c21 100644 --- a/nuttx/sched/wqueue/kwork_process.c +++ b/nuttx/sched/wqueue/kwork_process.c @@ -198,18 +198,26 @@ void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx) work = (FAR struct work_s *)work->dq.flink; } } - else + else /* elapsed < work->delay */ { - /* This one is not ready.. will it be ready before the next - * scheduled wakeup interval? + /* This one is not ready. * * NOTE that elapsed is relative to the the current time, * not the time of beginning of this queue processing pass. * So it may need an adjustment. */ - elapsed += (ctick - stick); - remaining = elapsed - work->delay; + elapsed += (ctick - stick); + if (elapsed > work->delay) + { + /* The delay has expired while we are processing */ + + elapsed = work->delay; + } + + /* Will it be ready before the next scheduled wakeup interval? */ + + remaining = work->delay - elapsed; if (remaining < next) { /* Yes.. Then schedule to wake up when the work is ready */ |