about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2023-04-18 19:01:37 +0200
committerjoboet <jonasboettiger@icloud.com>2024-02-09 14:58:38 +0100
commit8db64b5e2d442cb43830a8849e3549e4f8e20447 (patch)
tree6b07fbbb179178a2c47db10812de51269e838f7a
parent61ce691522a3c132ecd85294d2794cd3df160208 (diff)
downloadrust-8db64b5e2d442cb43830a8849e3549e4f8e20447.tar.gz
rust-8db64b5e2d442cb43830a8849e3549e4f8e20447.zip
use exponential backoff in `lock_contended`
-rw-r--r--library/std/src/sys/pal/unix/locks/queue_rwlock.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs
index 1a485b01f71..315c59a02d5 100644
--- a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs
+++ b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs
@@ -114,7 +114,7 @@ use crate::sync::atomic::{
 use crate::sys_common::thread_info;
 use crate::thread::Thread;
 
-const SPIN_COUNT: usize = 100;
+const SPIN_COUNT: usize = 6;
 
 type State = *mut ();
 type AtomicState = AtomicPtr<()>;
@@ -328,7 +328,9 @@ impl RwLock {
             } else if state.addr() & QUEUED == 0 && count < SPIN_COUNT {
                 // If the lock is not available but no threads are queued, spin
                 // for a while.
-                spin_loop();
+                for _ in 0..(1 << count) {
+                    spin_loop();
+                }
                 state = self.state.load(Relaxed);
                 count += 1;
             } else {