summaryrefslogtreecommitdiff
path: root/spinlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'spinlock.c')
-rw-r--r--spinlock.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/spinlock.c b/spinlock.c
index 891f72c..61ae093 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -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();
+}
+