Skip to content

Commit

Permalink
use asm() for lock release, not a C assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Sep 8, 2016
1 parent d63ac11 commit 34c2efc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ release(struct spinlock *lk)
// stores; __sync_synchronize() tells them both to not re-order.
__sync_synchronize();

// Release the lock.
lk->locked = 0;
// Release the lock, equivalent to lk->locked = 0.
// This code can't use a C assignment, since it might
// not be atomic.
asm volatile("movl $0, %0" : "+m" (lk->locked) : );

popcli();
}
Expand Down

0 comments on commit 34c2efc

Please sign in to comment.