diff --git a/lib/proc.c b/lib/proc.c index a55c8d6..66bca67 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -2,7 +2,20 @@ struct Cpu cpus[NCPU]; +/** + * Must be called with interrupts disabled, to prevent race with process being + * moved to a different CPU. + */ +int cpuid() { + int id = read_tp(); + return id; +} + /** * Return this CPU's cpu struct. Interrupts must be disabled. */ -inline struct Cpu *mycpu(void) { return &cpus[read_tp()]; } +struct Cpu *mycpu(void) { + int id = cpuid(); + struct Cpu *c = &cpus[id]; + return c; +}