diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index c3ddb5f38765..76648611c2d2 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -63,6 +63,8 @@ struct taskqueue { }; #define TQ_FLAGS_ACTIVE (1 << 0) +#define TQ_FLAGS_BLOCKED (1 << 1) +#define TQ_FLAGS_PENDING (1 << 2) static __inline void TQ_LOCK(struct taskqueue *tq) @@ -224,13 +226,38 @@ taskqueue_enqueue(struct taskqueue *queue, struct task *task) } task->ta_pending = 1; - queue->tq_enqueue(queue->tq_context); + if ((queue->tq_flags & TQ_FLAGS_BLOCKED) == 0) + queue->tq_enqueue(queue->tq_context); + else + queue->tq_flags |= TQ_FLAGS_PENDING; TQ_UNLOCK(queue); return 0; } +void +taskqueue_block(struct taskqueue *queue) +{ + + TQ_LOCK(queue); + queue->tq_flags |= TQ_FLAGS_BLOCKED; + TQ_UNLOCK(queue); +} + +void +taskqueue_unblock(struct taskqueue *queue) +{ + + TQ_LOCK(queue); + queue->tq_flags &= ~TQ_FLAGS_BLOCKED; + if (queue->tq_flags & TQ_FLAGS_PENDING) { + queue->tq_flags &= ~TQ_FLAGS_PENDING; + queue->tq_enqueue(queue->tq_context); + } + TQ_UNLOCK(queue); +} + void taskqueue_run(struct taskqueue *queue) { diff --git a/sys/sys/taskqueue.h b/sys/sys/taskqueue.h index c980fc187565..4065a58b3ed1 100644 --- a/sys/sys/taskqueue.h +++ b/sys/sys/taskqueue.h @@ -58,6 +58,8 @@ void taskqueue_drain(struct taskqueue *queue, struct task *task); struct taskqueue *taskqueue_find(const char *name); void taskqueue_free(struct taskqueue *queue); void taskqueue_run(struct taskqueue *queue); +void taskqueue_block(struct taskqueue *queue); +void taskqueue_unblock(struct taskqueue *queue); /* * Functions for dedicated thread taskqueues