From ec7abebc0b4707991dc1485b9332e2bd338bc4a3 Mon Sep 17 00:00:00 2001 From: jD91mZM2 <me@krake.one> Date: Thu, 27 Jun 2019 07:16:52 +0200 Subject: [PATCH] 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. --- src/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mutex.rs b/src/mutex.rs index 2c7d52a53..3e3d5df22 100644 --- a/src/mutex.rs +++ b/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); } -- GitLab