diff options
author | jhb <jhb@FreeBSD.org> | 2001-10-26 18:46:48 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2001-10-26 18:46:48 +0000 |
commit | 39b22ee16556aa5e491d4a88fd0f020f3cc5a963 (patch) | |
tree | 1cb183e25fc74879d8354cf488e60e59eb570fb4 /sys/kern/subr_taskqueue.c | |
parent | de855cd62618249bccc361160895e1506935c3b8 (diff) | |
download | FreeBSD-src-39b22ee16556aa5e491d4a88fd0f020f3cc5a963.zip FreeBSD-src-39b22ee16556aa5e491d4a88fd0f020f3cc5a963.tar.gz |
- Change the taskqueue locking to protect the necessary parts of a task
while it is on a queue with the queue lock and remove the per-task locks.
- Remove TASK_DESTROY now that it is no longer needed.
- Go back to inlining TASK_INIT now that it is short again.
Inspired by: dfr
Diffstat (limited to 'sys/kern/subr_taskqueue.c')
-rw-r--r-- | sys/kern/subr_taskqueue.c | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index e75a0c2..6052aea 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -29,9 +29,9 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/bus.h> +#include <sys/interrupt.h> #include <sys/kernel.h> #include <sys/lock.h> -#include <sys/interrupt.h> #include <sys/malloc.h> #include <sys/mutex.h> #include <sys/taskqueue.h> @@ -65,28 +65,6 @@ init_taskqueue_list(void *data __unused) SYSINIT(taskqueue_list, SI_SUB_INTRINSIC, SI_ORDER_ANY, init_taskqueue_list, NULL); -void -task_init(struct task *task, int priority, task_fn_t *func, void *context) -{ - - KASSERT(task != NULL, ("task == NULL")); - - mtx_init(&task->ta_mutex, "task", MTX_DEF); - mtx_lock(&task->ta_mutex); - task->ta_pending = 0; - task->ta_priority = priority; - task->ta_func = func; - task->ta_context = context; - mtx_unlock(&task->ta_mutex); -} - -void -task_destroy(struct task *task) -{ - - mtx_destroy(&task->ta_mutex); -} - struct taskqueue * taskqueue_create(const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context) @@ -156,10 +134,11 @@ taskqueue_enqueue(struct taskqueue *queue, struct task *task) struct task *ins; struct task *prev; + mtx_lock(&queue->tq_mutex); + /* * Don't allow new tasks on a queue which is being freed. */ - mtx_lock(&queue->tq_mutex); if (queue->tq_draining) { mtx_unlock(&queue->tq_mutex); return EPIPE; @@ -168,10 +147,8 @@ taskqueue_enqueue(struct taskqueue *queue, struct task *task) /* * Count multiple enqueues. */ - mtx_lock(&task->ta_mutex); if (task->ta_pending) { task->ta_pending++; - mtx_unlock(&task->ta_mutex); mtx_unlock(&queue->tq_mutex); return 0; } @@ -196,11 +173,11 @@ taskqueue_enqueue(struct taskqueue *queue, struct task *task) } task->ta_pending = 1; - mtx_unlock(&task->ta_mutex); - if (queue->tq_enqueue) queue->tq_enqueue(queue->tq_context); + mtx_unlock(&queue->tq_mutex); + return 0; } @@ -208,8 +185,6 @@ void taskqueue_run(struct taskqueue *queue) { struct task *task; - task_fn_t *saved_func; - void *arg; int pending; mtx_lock(&queue->tq_mutex); @@ -219,16 +194,12 @@ taskqueue_run(struct taskqueue *queue) * zero its pending count. */ task = STAILQ_FIRST(&queue->tq_queue); - mtx_lock(&task->ta_mutex); STAILQ_REMOVE_HEAD(&queue->tq_queue, ta_link); - mtx_unlock(&queue->tq_mutex); pending = task->ta_pending; task->ta_pending = 0; - saved_func = task->ta_func; - arg = task->ta_context; - mtx_unlock(&task->ta_mutex); + mtx_unlock(&queue->tq_mutex); - saved_func(arg, pending); + task->ta_func(task->ta_context, pending); mtx_lock(&queue->tq_mutex); } |