Fix a very slight error in the mutex
This was just my attempt at being smart, I didn't realize `compare_exchange` returned the old value (I'm dumb!), so I thought that if the value was 1 then it must have become 2. Normally with small errors like these you should leave a comment explaining why, but really, compare and *exchange* is pretty obvious. My bad.
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ impl<T> Mutex<T> {
|
||||
//
|
||||
// - Skip the atomic operation if the last value was 2, since it most likely hasn't changed.
|
||||
// - Skip the futex wait if the atomic operation says the mutex is unlocked.
|
||||
if last == 2 || self.atomic().compare_exchange(1, 2, SeqCst, SeqCst).unwrap_or_else(|err| err) == 2 {
|
||||
if last == 2 || self.atomic().compare_exchange(1, 2, SeqCst, SeqCst).unwrap_or_else(|err| err) != 0 {
|
||||
Sys::futex(self.atomic().get_mut(), FUTEX_WAIT, 2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user