]> Devi Nivas Git - cs3210-lab0.git/commitdiff
use asm() for lock release, not a C assignment
authorRobert Morris <rtm@csail.mit.edu>
Thu, 8 Sep 2016 18:45:20 +0000 (14:45 -0400)
committerRobert Morris <rtm@csail.mit.edu>
Thu, 8 Sep 2016 18:45:20 +0000 (14:45 -0400)
spinlock.c

index bf863ef104c3399c18ce628b7bae092df429b492..7b372ef3f1d1b016aa17d1dd07e8b5bdebced095 100644 (file)
@@ -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();
 }