aboutsummaryrefslogtreecommitdiff
path: root/src/ipi.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-02 21:40:10 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-02 21:40:10 +0300
commit8a3452098267e1af127d6c4f1836a9d82cd23f38 (patch)
treec9fad842a8903f64a57027b66ef54bba0dee2928 /src/ipi.c
parent7ad9c01dad7b1b46eced8290b8b991383d648188 (diff)
downloadkmi-8a3452098267e1af127d6c4f1836a9d82cd23f38.tar.gz
kmi-8a3452098267e1af127d6c4f1836a9d82cd23f38.zip
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
Diffstat (limited to 'src/ipi.c')
-rw-r--r--src/ipi.c26
1 files changed, 14 insertions, 12 deletions
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 <kmi/notify.h>
+#include <kmi/queue.h>
#include <kmi/ipi.h>
#include <arch/proc.h>
#include <arch/cpu.h>
+/** 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 */
}