From 14889b422910d683b06059f5b0eb340e4cc590d4 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Tue, 5 Oct 2004 04:16:01 +0000 Subject: Add taskqueue_drain. This waits for the specified task to finish, if running, or returns. The calling program is responsible for making sure that nothing new is enqueued. # man page coming soon. --- sys/kern/subr_taskqueue.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sys/kern/subr_taskqueue.c') diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index a10e7107bd89..7758fbdb1a27 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -186,11 +186,14 @@ taskqueue_run(struct taskqueue *queue) STAILQ_REMOVE_HEAD(&queue->tq_queue, ta_link); pending = task->ta_pending; task->ta_pending = 0; + task->ta_flags |= TAF_PENDING; mtx_unlock(&queue->tq_mutex); task->ta_func(task->ta_context, pending); mtx_lock(&queue->tq_mutex); + task->ta_flags &= ~TAF_PENDING; + wakeup(task); } /* @@ -201,6 +204,17 @@ taskqueue_run(struct taskqueue *queue) mtx_unlock(&queue->tq_mutex); } +void +taskqueue_drain(struct taskqueue *queue, struct task *task) +{ + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "taskqueue_drain"); + mtx_lock(&queue->tq_mutex); + while (task->ta_pending != 0 || (task->ta_flags & TAF_PENDING)) { + msleep(task, &queue->tq_mutex, PWAIT, "-", 0); + } + mtx_unlock(&queue->tq_mutex); +} + static void taskqueue_swi_enqueue(void *context) { -- cgit v1.2.3