Skip to content

Commit

Permalink
fix DOWNGRADED bit unpreserved
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
  • Loading branch information
connortsui20 and joboet committed Nov 16, 2024
1 parent 84fd95c commit 782b07e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/std/src/sync/rwlock/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/sync/rwlock/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 782b07e

Please sign in to comment.