From 8a3452098267e1af127d6c4f1836a9d82cd23f38 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 2 Jul 2024 21:40:10 +0300 Subject: more complete interrupt handling outline + Still largely untested, should really try to come up with a proper testsuite, at the moment it's mostly me trying things out in the (as of yet unreleased) kmx repo --- src/ipi.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/ipi.c') diff --git a/src/ipi.c b/src/ipi.c index 79b363f..e9bc4d3 100644 --- a/src/ipi.c +++ b/src/ipi.c @@ -2,27 +2,27 @@ /* Copyright 2023 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ #include +#include #include #include #include +/** List for keeping track of which threads have an ipi queued. */ +static struct queue_head fifo = INIT_QUEUE(fifo); + /** * @file ipi.c * * IPI function implementations. */ -bool clear_ipi(struct tcb *t) -{ - bool r = t->ipi; - t->ipi = false; - return r; -} - void send_ipi(struct tcb *t) { - t->ipi = true; + /** @todo this should probably have a spinlock guard */ + /** @todo killing a thread should make sure it gets removed from ipi + * queue */ + queue_push(&fifo, &t->ipi_queue); cpu_send_ipi(t->cpu_id); } @@ -31,9 +31,11 @@ void handle_ipi() struct tcb *t = cur_tcb(); adjust_ipi(t); - /** @todo how do we get the target thread? What if multiple threads send - * ipis at the same time? */ - struct tcb *r = NULL; - notify(r); + struct queue_head *q = queue_pop(&fifo); + if (!q) + return; + + struct tcb *r = container_of(q, struct tcb, ipi_queue); + notify(r, 0); /* notify didn't take for whatever reason so return whence we came from */ } -- cgit v1.3