@@ -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,20 +49,17 @@ 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 {
5456 scheduler. reschedule ( ) ;
5557
5658 let mut parking_lot = PARKING_LOT . lock ( ) ;
57- if wakeup_time. is_some_and ( |t| t <= get_timer_ticks ( ) ) {
59+ if matches ! ( wakeup_time, Some ( t ) if 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 ( ) {
@@ -72,9 +74,8 @@ pub fn futex_wait(address: &AtomicU32, expected: u32, timeout: Option<u64>, flag
7274 }
7375 } else {
7476 // If we are not in the waking queue, this must have been a wakeup.
75- let wakeup = !parking_lot
76- . get ( & address. as_mut_ptr ( ) . addr ( ) )
77- . is_some_and ( |queue| queue. contains ( handle) ) ;
77+ let wakeup = !matches ! ( parking_lot
78+ . get( & addr( address) ) , Some ( queue) if queue. contains( handle) ) ;
7879
7980 if wakeup {
8081 return 0 ;
@@ -97,7 +98,7 @@ pub fn futex_wake(address: &AtomicU32, count: i32) -> i32 {
9798 }
9899
99100 let mut parking_lot = PARKING_LOT . lock ( ) ;
100- let mut queue = match parking_lot. entry ( address . as_mut_ptr ( ) . addr ( ) ) {
101+ let mut queue = match parking_lot. entry ( addr ( address ) ) {
101102 Entry :: Occupied ( entry) => entry,
102103 Entry :: Vacant ( _) => return 0 ,
103104 } ;
0 commit comments