taskqueue_drain_all
Adrian Chadd
adrian at freebsd.org
Wed Oct 9 15:14:45 UTC 2013
+1
Very useful :)
-a
On 9 October 2013 01:55, Andriy Gapon <avg at freebsd.org> wrote:
>
> I would like to propose to extend taskqueue API with taskqueue_drain_all.
> A potential use case: I have a private taskqueue, several kinds of tasks
> get
> executed via it and then I want to make sure that all of them are
> completed.
> Obviously, I have a way to ensure that no new ones get enqueued.
>
> Is this a good addition?
> Or should like consider looping over all of my tasks externally to
> taskqueue
> implementation?
>
> A quick prototype:
>
> --- a/sys/kern/subr_taskqueue.c
> +++ b/sys/kern/subr_taskqueue.c
> @@ -316,6 +316,7 @@ taskqueue_run_locked(struct taskqueue *queue)
> wakeup(task);
> }
> TAILQ_REMOVE(&queue->tq_active, &tb, tb_link);
> + wakeup(&queue->tq_active);
> }
>
> void
> @@ -402,6 +403,22 @@ taskqueue_drain(struct taskqueue *queue, struct task
> *task)
> }
>
> void
> +taskqueue_drain_all(struct taskqueue *queue)
> +{
> + struct task *task;
> +
> + TQ_LOCK(queue);
> + while ((task = STAILQ_FIRST(&queue->tq_queue)) != NULL) {
> + while (task->ta_pending != 0 || task_is_running(queue,
> task))
> + TQ_SLEEP(queue, task, &queue->tq_mutex, PWAIT,
> "-", 0);
> + }
> + while (TAILQ_FIRST(&queue->tq_active) != NULL)
> + TQ_SLEEP(queue, &queue->tq_active,
> + &queue->tq_mutex, PWAIT, "-", 0);
> + TQ_UNLOCK(queue);
> +}
> +
> +void
> taskqueue_drain_timeout(struct taskqueue *queue,
> struct timeout_task *timeout_task)
> {
>
>
> --
> Andriy Gapon
>
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>
More information about the freebsd-hackers
mailing list