Don't spin on contended mutexes.

This commit is contained in:
Mara Bos 2022-04-01 11:11:46 +02:00
parent 6392f1555e
commit 321690c827

View File

@ -76,7 +76,9 @@ impl Mutex {
// while spinning, to be easier on the caches.
let state = self.futex.load(Relaxed);
if state == 0 || spin == 0 {
// We stop spinning when the mutex is unlocked (0),
// but also when it's contended (2).
if state != 1 || spin == 0 {
return state;
}