From 61ce691522a3c132ecd85294d2794cd3df160208 Mon Sep 17 00:00:00 2001 From: joboet Date: Tue, 18 Apr 2023 18:44:44 +0200 Subject: [PATCH] immediately register writer node if threads are queued --- library/std/src/sys/pal/unix/locks/queue_rwlock.rs | 5 +++-- 1 file 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 1719a56087a0..1a485b01f71c 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;