- 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
This commit is contained in:
parent
7d0080d583
commit
278282d97c
@ -434,9 +434,6 @@ aac_free(struct aac_softc *sc)
|
||||
if (sc->aac_regs_resource != NULL)
|
||||
bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
|
||||
sc->aac_regs_rid, sc->aac_regs_resource);
|
||||
#if __FreeBSD_version >= 500005
|
||||
TASK_DESTROY(&sc->aac_task_complete);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -113,7 +113,6 @@ AcpiOsExecuteQueue(void *arg, int pending)
|
||||
Function = (OSD_EXECUTION_CALLBACK)at->at_function;
|
||||
Context = at->at_context;
|
||||
|
||||
TASK_DESTROY(at);
|
||||
free(at, M_ACPITASK);
|
||||
|
||||
Function(Context);
|
||||
|
@ -320,10 +320,6 @@ amr_free(struct amr_softc *sc)
|
||||
TAILQ_REMOVE(&sc->amr_cmd_clusters, acc, acc_link);
|
||||
amr_freecmd_cluster(acc);
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 500005
|
||||
TASK_DESTROY(&sc->amr_task_complete);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -732,10 +732,6 @@ mly_free(struct mly_softc *sc)
|
||||
/* release the register window mapping */
|
||||
if (sc->mly_regs_resource != NULL)
|
||||
bus_release_resource(sc->mly_dev, SYS_RES_MEMORY, sc->mly_regs_rid, sc->mly_regs_resource);
|
||||
|
||||
#if __FreeBSD_version >= 500005
|
||||
TASK_DESTROY(&sc->mly_task_complete);
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -34,8 +34,6 @@
|
||||
#endif
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include <sys/_lock.h>
|
||||
#include <sys/_mutex.h>
|
||||
|
||||
struct taskqueue;
|
||||
|
||||
@ -62,12 +60,8 @@ struct task {
|
||||
int ta_priority; /* priority of task in queue */
|
||||
task_fn_t *ta_func; /* task handler */
|
||||
void *ta_context; /* argument for handler */
|
||||
struct mtx ta_mutex; /* lock for each task */
|
||||
};
|
||||
|
||||
void task_init(struct task *task, int priority, task_fn_t *func,
|
||||
void *context);
|
||||
void task_destroy(struct task *task);
|
||||
struct taskqueue *taskqueue_create(const char *name, int mflags,
|
||||
taskqueue_enqueue_fn enqueue,
|
||||
void *context);
|
||||
@ -79,14 +73,12 @@ void taskqueue_run(struct taskqueue *queue);
|
||||
/*
|
||||
* Initialise a task structure.
|
||||
*/
|
||||
#define TASK_INIT(task, priority, func, context) \
|
||||
task_init((task), (priority), (func), (context))
|
||||
|
||||
/*
|
||||
* Destroy a task structure.
|
||||
*/
|
||||
#define TASK_DESTROY(task) \
|
||||
task_destroy((task))
|
||||
#define TASK_INIT(task, priority, func, context) do { \
|
||||
(task)->ta_pending = 0; \
|
||||
(task)->ta_priority = (priority); \
|
||||
(task)->ta_func = (func); \
|
||||
(task)->ta_context = (context); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Declare a reference to a taskqueue.
|
||||
|
Loading…
Reference in New Issue
Block a user