Skip to content

Commit

Permalink
comment memory barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Sep 7, 2006
1 parent 0b75a8e commit e7a5b3c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down

0 comments on commit e7a5b3c

Please sign in to comment.