MPSAFE locking
* Simplify taskqueue locking. * Don't acquire Giant around calls to the taskqueue function. * Remove 4.x compatibility routines.
This commit is contained in:
parent
d49f14c7b2
commit
e7ca6bbdad
@ -69,7 +69,6 @@ struct acpi_task_queue {
|
||||
struct acpi_task *at;
|
||||
};
|
||||
|
||||
#if __FreeBSD_version >= 500000
|
||||
/*
|
||||
* Private task queue definition for ACPI
|
||||
*/
|
||||
@ -92,9 +91,8 @@ TASKQUEUE_DEFINE(acpi, taskqueue_acpi_enqueue, 0,
|
||||
swi_add(NULL, "acpitaskq", taskqueue_acpi_run, NULL,
|
||||
SWI_TQ, 0, &taskqueue_acpi_ih));
|
||||
|
||||
#ifdef ACPI_USE_THREADS
|
||||
static STAILQ_HEAD(, acpi_task_queue) acpi_task_queue;
|
||||
static struct mtx acpi_task_mtx;
|
||||
ACPI_LOCK_DECL(taskq, "ACPI task queue");
|
||||
|
||||
static void
|
||||
acpi_task_thread(void *arg)
|
||||
@ -103,26 +101,21 @@ acpi_task_thread(void *arg)
|
||||
OSD_EXECUTION_CALLBACK Function;
|
||||
void *Context;
|
||||
|
||||
ACPI_LOCK(taskq);
|
||||
for (;;) {
|
||||
mtx_lock(&acpi_task_mtx);
|
||||
if ((atq = STAILQ_FIRST(&acpi_task_queue)) == NULL) {
|
||||
msleep(&acpi_task_queue, &acpi_task_mtx, PCATCH, "actask", 0);
|
||||
mtx_unlock(&acpi_task_mtx);
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((atq = STAILQ_FIRST(&acpi_task_queue)) == NULL)
|
||||
msleep(&acpi_task_queue, &taskq_mutex, PCATCH, "actask", 0);
|
||||
STAILQ_REMOVE_HEAD(&acpi_task_queue, at_q);
|
||||
mtx_unlock(&acpi_task_mtx);
|
||||
ACPI_UNLOCK(taskq);
|
||||
|
||||
Function = (OSD_EXECUTION_CALLBACK)atq->at->at_function;
|
||||
Context = atq->at->at_context;
|
||||
|
||||
mtx_lock(&Giant);
|
||||
Function(Context);
|
||||
|
||||
free(atq->at, M_ACPITASK);
|
||||
free(atq, M_ACPITASK);
|
||||
mtx_unlock(&Giant);
|
||||
ACPI_LOCK(taskq);
|
||||
}
|
||||
|
||||
kthread_exit(0);
|
||||
@ -136,7 +129,6 @@ acpi_task_thread_init(void)
|
||||
|
||||
err = 0;
|
||||
STAILQ_INIT(&acpi_task_queue);
|
||||
mtx_init(&acpi_task_mtx, "ACPI task", NULL, MTX_DEF);
|
||||
|
||||
for (i = 0; i < ACPI_MAX_THREADS; i++) {
|
||||
err = kthread_create(acpi_task_thread, NULL, &acpi_kthread_proc,
|
||||
@ -148,8 +140,6 @@ acpi_task_thread_init(void)
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
#endif /* ACPI_USE_THREADS */
|
||||
#endif /* __FreeBSD_version >= 500000 */
|
||||
|
||||
/* This function is called in interrupt context. */
|
||||
ACPI_STATUS
|
||||
@ -189,11 +179,7 @@ AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function,
|
||||
}
|
||||
TASK_INIT(&at->at_task, pri, AcpiOsExecuteQueue, at);
|
||||
|
||||
#if __FreeBSD_version >= 500000
|
||||
taskqueue_enqueue(taskqueue_acpi, (struct task *)at);
|
||||
#else
|
||||
taskqueue_enqueue(taskqueue_swi, (struct task *)at);
|
||||
#endif
|
||||
|
||||
return_ACPI_STATUS (AE_OK);
|
||||
}
|
||||
@ -201,38 +187,27 @@ AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function,
|
||||
static void
|
||||
AcpiOsExecuteQueue(void *arg, int pending)
|
||||
{
|
||||
struct acpi_task *at;
|
||||
struct acpi_task_queue *atq;
|
||||
OSD_EXECUTION_CALLBACK Function;
|
||||
void *Context;
|
||||
|
||||
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
||||
|
||||
at = (struct acpi_task *)arg;
|
||||
atq = NULL;
|
||||
Function = NULL;
|
||||
Context = NULL;
|
||||
|
||||
#ifdef ACPI_USE_THREADS
|
||||
atq = malloc(sizeof(*atq), M_ACPITASK, M_NOWAIT);
|
||||
if (atq == NULL) {
|
||||
printf("%s: no memory\n", __func__);
|
||||
return;
|
||||
}
|
||||
atq->at = (struct acpi_task *)arg;
|
||||
|
||||
atq->at = at;
|
||||
|
||||
mtx_lock(&acpi_task_mtx);
|
||||
ACPI_LOCK(taskq);
|
||||
STAILQ_INSERT_TAIL(&acpi_task_queue, atq, at_q);
|
||||
mtx_unlock(&acpi_task_mtx);
|
||||
wakeup_one(&acpi_task_queue);
|
||||
#else
|
||||
Function = (OSD_EXECUTION_CALLBACK)at->at_function;
|
||||
Context = at->at_context;
|
||||
|
||||
Function(Context);
|
||||
free(at, M_ACPITASK);
|
||||
#endif
|
||||
ACPI_UNLOCK(taskq);
|
||||
|
||||
return_VOID;
|
||||
}
|
||||
@ -276,10 +251,6 @@ AcpiOsGetThreadId(void)
|
||||
/* XXX do not add ACPI_FUNCTION_TRACE here, results in recursive call. */
|
||||
|
||||
p = curproc;
|
||||
#if __FreeBSD_version < 500000
|
||||
if (p == NULL)
|
||||
p = &proc0;
|
||||
#endif
|
||||
KASSERT(p != NULL, ("%s: curproc is NULL!", __func__));
|
||||
|
||||
/* Returning 0 is not allowed. */
|
||||
|
Loading…
Reference in New Issue
Block a user