diff --git a/kernel-src/include/kernel/dpc.h b/kernel-src/include/kernel/dpc.h index 1d14bdbe..091ee042 100644 --- a/kernel-src/include/kernel/dpc.h +++ b/kernel-src/include/kernel/dpc.h @@ -3,13 +3,13 @@ #include #include +#include typedef void * dpcarg_t; typedef void (*dpcfn_t)(context_t *, dpcarg_t); typedef struct _dpc_t { - struct _dpc_t *next; - struct _dpc_t *prev; + list_node_t list_node; bool enqueued; dpcfn_t fn; dpcarg_t arg; diff --git a/kernel-src/include/x86-64/arch/cpu.h b/kernel-src/include/x86-64/arch/cpu.h index 3a34c003..7ff3778a 100644 --- a/kernel-src/include/x86-64/arch/cpu.h +++ b/kernel-src/include/x86-64/arch/cpu.h @@ -46,7 +46,7 @@ typedef struct cpu_t { timer_t *timer; isr_t *dpcisr; - dpc_t *dpcqueue; + list_t dpcqueue; thread_t *idlethread; timerentry_t schedtimerentry; diff --git a/kernel-src/sys/dpc.c b/kernel-src/sys/dpc.c index a7701074..1b7835f1 100644 --- a/kernel-src/sys/dpc.c +++ b/kernel-src/sys/dpc.c @@ -4,30 +4,10 @@ #include -static void remove(dpc_t *dpc) { - if (dpc->prev) - dpc->prev->next = dpc->next; - else - current_cpu()->dpcqueue = dpc->next; - - if (dpc->next) - dpc->next->prev = dpc->prev; -} - -static void insert(dpc_t *dpc) { - dpc->prev = NULL; - dpc->next = current_cpu()->dpcqueue; - - if (dpc->next) - dpc->next->prev = dpc; - - current_cpu()->dpcqueue = dpc; -} - static void isrfn(isr_t *self, context_t *context) { - while (current_cpu()->dpcqueue) { - dpc_t *dpc = current_cpu()->dpcqueue; - remove(dpc); + list_node_t *node; + while ((node = list_pop_front(¤t_cpu()->dpcqueue)) != NULL) { + dpc_t *dpc = (dpc_t *)node; dpcarg_t arg = dpc->arg; __assert(dpc->enqueued); @@ -42,8 +22,8 @@ static void isrfn(isr_t *self, context_t *context) { void dpc_prepare(dpc_t *dpc, dpcfn_t fn) { dpc->fn = fn; dpc->enqueued = false; - dpc->next = NULL; - dpc->prev = NULL; + dpc->list_node.next = NULL; + dpc->list_node.prev = NULL; } void dpc_enqueue(dpc_t *dpc, dpcarg_t arg) { @@ -54,7 +34,7 @@ void dpc_enqueue(dpc_t *dpc, dpcarg_t arg) { dpc->arg = arg; dpc->enqueued = true; - insert(dpc); + list_push_front(¤t_cpu()->dpcqueue, &dpc->list_node); interrupt_raise(current_cpu()->dpcisr); cleanup: @@ -68,13 +48,14 @@ void dpc_dequeue(dpc_t *dpc) { goto cleanup; dpc->enqueued = false; - remove(dpc); + list_remove(&dpc->list_node); cleanup: interrupt_set(entrystate); } void dpc_init() { + list_init(¤t_cpu()->dpcqueue); current_cpu()->dpcisr = interrupt_allocate(isrfn, NULL, IPL_DPC); __assert(current_cpu()->dpcisr); }