diff options
Diffstat (limited to 'spinlock.c')
-rw-r--r-- | spinlock.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -25,13 +25,10 @@ initlock(struct spinlock *lock, char *name) void acquire(struct spinlock *lock) { + splhi(); if(holding(lock)) panic("acquire"); - if(cpus[cpu()].nlock == 0) - cli(); - cpus[cpu()].nlock++; - while(cmpxchg(0, 1, &lock->locked) == 1) ; @@ -62,8 +59,7 @@ release(struct spinlock *lock) cpuid(0, 0, 0, 0, 0); // memory barrier (see Ch 7, IA-32 manual vol 3) lock->locked = 0; - if(--cpus[cpu()].nlock == 0) - sti(); + spllo(); } // Record the current call stack in pcs[] by following the %ebp chain. @@ -91,3 +87,26 @@ holding(struct spinlock *lock) return lock->locked && lock->cpu == cpu() + 10; } + + +// XXX! +// Better names? Better functions? + +void +splhi(void) +{ + cli(); + cpus[cpu()].nsplhi++; +} + +void +spllo(void) +{ + if(read_eflags()&FL_IF) + panic("spllo - interruptible"); + if(--cpus[cpu()].nsplhi < 0) + panic("spllo"); + if(cpus[cpu()].nsplhi == 0) + sti(); +} + |