From 782b07e1ff4a4f8ecf00d5e030dfead9222d2185 Mon Sep 17 00:00:00 2001 From: Connor Tsui <87130162+connortsui20@users.noreply.github.com> Date: Sat, 16 Nov 2024 12:22:35 -0500 Subject: [PATCH] fix `DOWNGRADED` bit unpreserved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jonas Böttiger --- library/std/src/sync/rwlock/tests.rs | 2 +- library/std/src/sys/sync/rwlock/queue.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/sync/rwlock/tests.rs b/library/std/src/sync/rwlock/tests.rs index 4f30ef3cac398..5413a062cef35 100644 --- a/library/std/src/sync/rwlock/tests.rs +++ b/library/std/src/sync/rwlock/tests.rs @@ -558,7 +558,7 @@ fn test_downgrade_atomic() { // modify the protected value. // `W` is the number of evil writer threads. - const W: usize = if cfg!(target_pointer_width = "64") { 100 } else { 20 }; + const W: usize = 20; let rwlock = Arc::new(RwLock::new(0)); // Spawns many evil writer threads that will try and write to the locked value before the diff --git a/library/std/src/sys/sync/rwlock/queue.rs b/library/std/src/sys/sync/rwlock/queue.rs index c654fca0d6e96..51330f8fafe57 100644 --- a/library/std/src/sys/sync/rwlock/queue.rs +++ b/library/std/src/sys/sync/rwlock/queue.rs @@ -395,9 +395,9 @@ impl RwLock { node.next.0 = AtomicPtr::new(state.mask(NODE_MASK).cast()); node.prev = AtomicLink::new(None); - // Set the `QUEUED` bit and maintain the `LOCKED` bit. + // Set the `QUEUED` bit and preserve the `LOCKED` and `DOWNGRADED` bit. let mut next = ptr::from_ref(&node) - .map_addr(|addr| addr | QUEUED | (state.addr() & LOCKED)) + .map_addr(|addr| addr | QUEUED | (state.addr() & (DOWNGRADED | LOCKED))) as State; let mut is_queue_locked = false;