about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2023-04-18 18:44:44 +0200
committerjoboet <jonasboettiger@icloud.com>2024-02-09 14:58:38 +0100
commit61ce691522a3c132ecd85294d2794cd3df160208 (patch)
treebd03d467c34af642eac7a9cec24f7150132d2966
parent709ccf98b8f646629150c9b1dfa536dd2b905d10 (diff)
downloadrust-61ce691522a3c132ecd85294d2794cd3df160208.tar.gz
rust-61ce691522a3c132ecd85294d2794cd3df160208.zip
immediately register writer node if threads are queued
-rw-r--r--library/std/src/sys/pal/unix/locks/queue_rwlock.rs5
1 files changed, 3 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 1719a56087a..1a485b01f71 100644
--- a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs
+++ b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs
@@ -325,8 +325,9 @@ impl RwLock {
                     Ok(_) => return,
                     Err(new) => state = new,
                 }
-            } else if count < SPIN_COUNT {
-                // If the lock is not available, spin for a while.
+            } 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();
                 state = self.state.load(Relaxed);
                 count += 1;