Fix backward calculation in the work queue timing. From Liio Chen via the PX4 repository

This commit is contained in:
Gregory Nutt 2015-01-27 06:17:02 -06:00
parent ea5fdeea20
commit 6bc9a0c9c6
2 changed files with 26 additions and 10 deletions

View File

@ -219,18 +219,26 @@ void work_process(FAR struct usr_wqueue_s *wqueue)
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 */

View File

@ -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 */