Add a special meaning to the negative ticks argument for

taskqueue_enqueue_timeout().  Do not rearm the callout if it is
already armed and the ticks is negative.  Otherwise rearm it to fire
in abs(ticks) ticks in the future.

The intended use is to call taskqueue_enqueue_timeout() for the given
timeout_task with the same negative ticks argument.  As result, the
task is scheduled to execute not further than abs(ticks) ticks in
future, and the consequent enqueues are coalesced until the already
scheduled task is finished.

Reviewed by:	rwatson
Tested by:	Markus Gebert <markus.gebert@hostpoint.ch>
MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2012-11-20 15:33:48 +00:00
parent 6db79c26ce
commit b7c8d2f2f5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=243341

View File

@ -252,9 +252,13 @@ taskqueue_enqueue_timeout(struct taskqueue *queue,
} else {
queue->tq_callouts++;
timeout_task->f |= DT_CALLOUT_ARMED;
if (ticks < 0)
ticks = -ticks; /* Ignore overflow. */
}
if (ticks > 0) {
callout_reset(&timeout_task->c, ticks,
taskqueue_timeout_func, timeout_task);
}
callout_reset(&timeout_task->c, ticks, taskqueue_timeout_func,
timeout_task);
}
TQ_UNLOCK(queue);
return (res);