From a3e45d5dcaf1bf3a9e684b5fcc301413ec994a9b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 9 Nov 2022 16:27:23 +0200 Subject: add basic IPI structure --- common/tcb.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'common/tcb.c') diff --git a/common/tcb.c b/common/tcb.c index 9000941..417ca45 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -36,7 +36,7 @@ static struct tcb **tcbs; * \todo If we ever support systems with massive amounts of cpus, this should probably * be allocated at runtime. */ -static struct tcb *cpu_tcb[MAX_CPUS] = { 0 }; +static struct tcb *__cpu_tcb[MAX_CPUS] = { 0 }; void init_tcbs() { @@ -294,7 +294,12 @@ DEFINE_DETACH(detach_proc, proc); /* weak to allow optimisation on risc-v, but provide fallback for future */ __weak struct tcb *cur_tcb() { - return cpu_tcb[cpu_id()]; + return cpu_tcb(cpu_id()); +} + +struct tcb *cpu_tcb(id_t cpu_id) +{ + return __cpu_tcb[cpu_id]; } struct tcb *cur_proc() @@ -313,7 +318,7 @@ void use_tcb(struct tcb *t) { cpu_assign(t); - cpu_tcb[t->cpu_id] = t; + __cpu_tcb[t->cpu_id] = t; use_vmem(t->proc.vmem); } @@ -355,3 +360,8 @@ void set_return(struct tcb *t, vm_t v) { t->exec = v; } + +bool running(struct tcb *t) +{ + return cpu_tcb(t->cpu_id) == t; +} -- cgit v1.3