Browse Source

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.
jD91mZM2 5 years ago
parent
commit
ec7abebc0b
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/mutex.rs

+ 1 - 1
src/mutex.rs

@@ -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);
             }