summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <rsc>2006-09-07 16:53:49 +0000
committerrsc <rsc>2006-09-07 16:53:49 +0000
commite7a5b3c5ee2d440892ab7e9bb98ad82efb25219f (patch)
tree55d1c20e3a0c7043987cddcc84119f28adb547bf
parent0b75a8e8bea4f4c8230daae8d81eda04c19e622c (diff)
downloadxv6-labs-e7a5b3c5ee2d440892ab7e9bb98ad82efb25219f.tar.gz
xv6-labs-e7a5b3c5ee2d440892ab7e9bb98ad82efb25219f.tar.bz2
xv6-labs-e7a5b3c5ee2d440892ab7e9bb98ad82efb25219f.zip
comment memory barriers
-rw-r--r--spinlock.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/spinlock.c b/spinlock.c
index 486c217..2e604b7 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -50,6 +50,10 @@ acquire(struct spinlock *lock)
while(cmpxchg(0, 1, &lock->locked) == 1)
;
+
+ // Now that lock is acquired, make sure
+ // we wait for all pending writes from other
+ // processors.
cpuid(0, 0, 0, 0, 0); // memory barrier
// Record info about lock acquisition for debugging.
@@ -64,13 +68,16 @@ acquire(struct spinlock *lock)
void
release(struct spinlock *lock)
{
-
if(!holding(lock))
panic("release");
lock->pcs[0] = 0;
lock->cpu = 0xffffffff;
+
+ // Before unlocking the lock, make sure to flush
+ // any pending memory writes from this processor.
cpuid(0, 0, 0, 0, 0); // memory barrier
+
lock->locked = 0;
if(--cpus[cpu()].nlock == 0)
sti();