diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-04-01 11:11:46 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-04-01 11:11:46 +0200 |
| commit | 321690c8278a5cf038adc50d1642c8e158de38a7 (patch) | |
| tree | 6ce4672c3f0fa32c9eafd85b827697265e63e107 /library/std/src/sys | |
| parent | 6392f1555e6515c59faa8393d1bf106b0c8872bd (diff) | |
| download | rust-321690c8278a5cf038adc50d1642c8e158de38a7.tar.gz rust-321690c8278a5cf038adc50d1642c8e158de38a7.zip | |
Don't spin on contended mutexes.
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/unix/locks/futex.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/locks/futex.rs b/library/std/src/sys/unix/locks/futex.rs index 08c042f279b..d9b5bfe3ac6 100644 --- a/library/std/src/sys/unix/locks/futex.rs +++ b/library/std/src/sys/unix/locks/futex.rs @@ -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; } |
