Skip to content

Commit 86ec272

Browse files
committed
Disable atomic_mut_ptr feature
Futex: Use outer atomic ptr
1 parent 1969bd5 commit 86ec272

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#![allow(incomplete_features)]
1010
#![feature(abi_x86_interrupt)]
1111
#![feature(allocator_api)]
12-
#![feature(atomic_mut_ptr)]
1312
#![feature(asm_const)]
1413
#![feature(linked_list_cursors)]
1514
#![feature(naked_functions)]

src/synch/futex.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ bitflags! {
2222
}
2323
}
2424

25+
fn addr(addr: &AtomicU32) -> usize {
26+
let ptr: *const _ = addr;
27+
ptr.addr()
28+
}
29+
2530
/// If the value at address matches the expected value, park the current thread until it is either
2631
/// woken up with `futex_wake` (returns 0) or the specified timeout elapses (returns -ETIMEDOUT).
2732
///
@@ -44,10 +49,7 @@ pub fn futex_wait(address: &AtomicU32, expected: u32, timeout: Option<u64>, flag
4449
let scheduler = core_scheduler();
4550
scheduler.block_current_task(wakeup_time);
4651
let handle = scheduler.get_current_task_handle();
47-
parking_lot
48-
.entry(address.as_mut_ptr().addr())
49-
.or_default()
50-
.push(handle);
52+
parking_lot.entry(addr(address)).or_default().push(handle);
5153
drop(parking_lot);
5254

5355
loop {
@@ -57,7 +59,7 @@ pub fn futex_wait(address: &AtomicU32, expected: u32, timeout: Option<u64>, flag
5759
if wakeup_time.is_some_and(|t| t <= get_timer_ticks()) {
5860
let mut wakeup = true;
5961
// Timeout occurred, try to remove ourselves from the waiting queue.
60-
if let Entry::Occupied(mut queue) = parking_lot.entry(address.as_mut_ptr().addr()) {
62+
if let Entry::Occupied(mut queue) = parking_lot.entry(addr(address)) {
6163
// If we are not in the waking queue, this must have been a wakeup.
6264
wakeup = !queue.get_mut().remove(handle);
6365
if queue.get().is_empty() {
@@ -73,7 +75,7 @@ pub fn futex_wait(address: &AtomicU32, expected: u32, timeout: Option<u64>, flag
7375
} else {
7476
// If we are not in the waking queue, this must have been a wakeup.
7577
let wakeup = !parking_lot
76-
.get(&address.as_mut_ptr().addr())
78+
.get(&addr(address))
7779
.is_some_and(|queue| queue.contains(handle));
7880

7981
if wakeup {
@@ -97,7 +99,7 @@ pub fn futex_wake(address: &AtomicU32, count: i32) -> i32 {
9799
}
98100

99101
let mut parking_lot = PARKING_LOT.lock();
100-
let mut queue = match parking_lot.entry(address.as_mut_ptr().addr()) {
102+
let mut queue = match parking_lot.entry(addr(address)) {
101103
Entry::Occupied(entry) => entry,
102104
Entry::Vacant(_) => return 0,
103105
};

0 commit comments

Comments
 (0)