Skip to content

Commit 61ce691

Browse files
committed
immediately register writer node if threads are queued
1 parent 709ccf9 commit 61ce691

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/sys/pal/unix/locks/queue_rwlock.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,9 @@ impl RwLock {
325325
Ok(_) => return,
326326
Err(new) => state = new,
327327
}
328-
} else if count < SPIN_COUNT {
329-
// If the lock is not available, spin for a while.
328+
} else if state.addr() & QUEUED == 0 && count < SPIN_COUNT {
329+
// If the lock is not available but no threads are queued, spin
330+
// for a while.
330331
spin_loop();
331332
state = self.state.load(Relaxed);
332333
count += 1;

0 commit comments

Comments
 (0)