Skip to content
Snippets Groups Projects
Commit e7a5b3c5 authored by rsc's avatar rsc
Browse files

comment memory barriers

parent 0b75a8e8
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,10 @@ acquire(struct spinlock *lock) ...@@ -50,6 +50,10 @@ acquire(struct spinlock *lock)
while(cmpxchg(0, 1, &lock->locked) == 1) 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 cpuid(0, 0, 0, 0, 0); // memory barrier
// Record info about lock acquisition for debugging. // Record info about lock acquisition for debugging.
...@@ -64,13 +68,16 @@ acquire(struct spinlock *lock) ...@@ -64,13 +68,16 @@ acquire(struct spinlock *lock)
void void
release(struct spinlock *lock) release(struct spinlock *lock)
{ {
if(!holding(lock)) if(!holding(lock))
panic("release"); panic("release");
lock->pcs[0] = 0; lock->pcs[0] = 0;
lock->cpu = 0xffffffff; 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 cpuid(0, 0, 0, 0, 0); // memory barrier
lock->locked = 0; lock->locked = 0;
if(--cpus[cpu()].nlock == 0) if(--cpus[cpu()].nlock == 0)
sti(); sti();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment