kernel: use list.h for DPC queues

This commit is contained in:
wnstngs
2026-10-07 10:23:18 +03:00
parent 90cbe1d6aa
commit 3894be1a15
3 changed files with 11 additions and 30 deletions
+2 -2
View File
@@ -3,13 +3,13 @@
#include <arch/context.h> #include <arch/context.h>
#include <stdbool.h> #include <stdbool.h>
#include <list.h>
typedef void * dpcarg_t; typedef void * dpcarg_t;
typedef void (*dpcfn_t)(context_t *, dpcarg_t); typedef void (*dpcfn_t)(context_t *, dpcarg_t);
typedef struct _dpc_t { typedef struct _dpc_t {
struct _dpc_t *next; list_node_t list_node;
struct _dpc_t *prev;
bool enqueued; bool enqueued;
dpcfn_t fn; dpcfn_t fn;
dpcarg_t arg; dpcarg_t arg;
+1 -1
View File
@@ -46,7 +46,7 @@ typedef struct cpu_t {
timer_t *timer; timer_t *timer;
isr_t *dpcisr; isr_t *dpcisr;
dpc_t *dpcqueue; list_t dpcqueue;
thread_t *idlethread; thread_t *idlethread;
timerentry_t schedtimerentry; timerentry_t schedtimerentry;
+8 -27
View File
@@ -4,30 +4,10 @@
#include <logging.h> #include <logging.h>
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) { static void isrfn(isr_t *self, context_t *context) {
while (current_cpu()->dpcqueue) { list_node_t *node;
dpc_t *dpc = current_cpu()->dpcqueue; while ((node = list_pop_front(&current_cpu()->dpcqueue)) != NULL) {
remove(dpc); dpc_t *dpc = (dpc_t *)node;
dpcarg_t arg = dpc->arg; dpcarg_t arg = dpc->arg;
__assert(dpc->enqueued); __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) { void dpc_prepare(dpc_t *dpc, dpcfn_t fn) {
dpc->fn = fn; dpc->fn = fn;
dpc->enqueued = false; dpc->enqueued = false;
dpc->next = NULL; dpc->list_node.next = NULL;
dpc->prev = NULL; dpc->list_node.prev = NULL;
} }
void dpc_enqueue(dpc_t *dpc, dpcarg_t arg) { 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->arg = arg;
dpc->enqueued = true; dpc->enqueued = true;
insert(dpc); list_push_front(&current_cpu()->dpcqueue, &dpc->list_node);
interrupt_raise(current_cpu()->dpcisr); interrupt_raise(current_cpu()->dpcisr);
cleanup: cleanup:
@@ -68,13 +48,14 @@ void dpc_dequeue(dpc_t *dpc) {
goto cleanup; goto cleanup;
dpc->enqueued = false; dpc->enqueued = false;
remove(dpc); list_remove(&dpc->list_node);
cleanup: cleanup:
interrupt_set(entrystate); interrupt_set(entrystate);
} }
void dpc_init() { void dpc_init() {
list_init(&current_cpu()->dpcqueue);
current_cpu()->dpcisr = interrupt_allocate(isrfn, NULL, IPL_DPC); current_cpu()->dpcisr = interrupt_allocate(isrfn, NULL, IPL_DPC);
__assert(current_cpu()->dpcisr); __assert(current_cpu()->dpcisr);
} }