summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/subr_taskqueue.c17
-rw-r--r--sys/sys/taskqueue.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c
index d380b9cbd3a7..9130716d2a25 100644
--- a/sys/kern/subr_taskqueue.c
+++ b/sys/kern/subr_taskqueue.c
@@ -487,6 +487,23 @@ task_is_running(struct taskqueue *queue, struct task *task)
return (0);
}
+/*
+ * Only use this function in single threaded contexts. It returns
+ * non-zero if the given task is either pending or running. Else the
+ * task is idle and can be queued again or freed.
+ */
+int
+taskqueue_poll_is_busy(struct taskqueue *queue, struct task *task)
+{
+ int retval;
+
+ TQ_LOCK(queue);
+ retval = task->ta_pending > 0 || task_is_running(queue, task);
+ TQ_UNLOCK(queue);
+
+ return (retval);
+}
+
static int
taskqueue_cancel_locked(struct taskqueue *queue, struct task *task,
u_int *pendp)
diff --git a/sys/sys/taskqueue.h b/sys/sys/taskqueue.h
index a6c6655832ec..0e76599e4b39 100644
--- a/sys/sys/taskqueue.h
+++ b/sys/sys/taskqueue.h
@@ -79,6 +79,7 @@ int taskqueue_start_threads_cpuset(struct taskqueue **tqp, int count,
int taskqueue_enqueue(struct taskqueue *queue, struct task *task);
int taskqueue_enqueue_timeout(struct taskqueue *queue,
struct timeout_task *timeout_task, int ticks);
+int taskqueue_poll_is_busy(struct taskqueue *queue, struct task *task);
int taskqueue_cancel(struct taskqueue *queue, struct task *task,
u_int *pendp);
int taskqueue_cancel_timeout(struct taskqueue *queue,