@@ -12,7 +12,7 @@ struct SleepState(AtomicU8);
1212
1313/// # Race condition prevention
1414///
15- /// Two methods matter here: [ crate::arch::interrupts::enable_and_wait] and [ crate::arch::wakeup_core] .
15+ /// Two methods matter here: ` crate::arch::interrupts::enable_and_wait` and ` crate::arch::wakeup_core` .
1616/// `enable_and_wait` checks the status, ensuring it is set to 0+setting it to 1, then sleeps.
1717/// `wakeup_core` checks the status, ensuring it is set to 1+setting it to 0, then issues interrupt.
1818///
@@ -34,12 +34,12 @@ impl SleepState {
3434 const STATUS_DONT_SLEEP : u8 = 2 ;
3535
3636 fn new ( ) -> Self {
37- Self ( AtomicU8 :: new ( SleepState :: STATUS_ACTIVE ) )
37+ Self ( AtomicU8 :: new ( Self :: STATUS_ACTIVE ) )
3838 }
3939
4040 #[ inline]
4141 fn set_active ( & self ) {
42- self . 0 . store ( SleepState :: STATUS_ACTIVE , Ordering :: SeqCst ) ;
42+ self . 0 . store ( Self :: STATUS_ACTIVE , Ordering :: SeqCst ) ;
4343 }
4444
4545 /// Indicates that this core will go to HLT.
@@ -49,8 +49,8 @@ impl SleepState {
4949 if self
5050 . 0
5151 . compare_exchange (
52- SleepState :: STATUS_ACTIVE ,
53- SleepState :: STATUS_IDLE ,
52+ Self :: STATUS_ACTIVE ,
53+ Self :: STATUS_IDLE ,
5454 Ordering :: SeqCst ,
5555 Ordering :: Relaxed ,
5656 )
@@ -84,10 +84,10 @@ impl SleepState {
8484 // Ask the core not to sleep.
8585 // This makes sure that if the two atomic operations become interleaved, the core will
8686 // not go to sleep with us assuming it was running.
87- let previous_state = self . 0 . swap ( SleepState :: STATUS_DONT_SLEEP , Ordering :: SeqCst ) ;
87+ let previous_state = self . 0 . swap ( Self :: STATUS_DONT_SLEEP , Ordering :: SeqCst ) ;
8888
8989 // If the core was idle, we can actually wake it up
90- if previous_state == SleepState :: STATUS_IDLE {
90+ if previous_state == Self :: STATUS_IDLE {
9191 // Again, this operation is not necessarily ordered.
9292 // - Another `go_to_sleep` could be processing, either BEFORE or AFTER the atomic op.
9393 // * BEFORE:
@@ -119,12 +119,17 @@ pub(super) fn install_for_core(core_id: CoreId) {
119119 . insert ( core_id. try_into ( ) . unwrap ( ) , SleepState :: new ( ) ) ;
120120}
121121
122+ /// Tries to put the core to sleep.
123+ /// Returns `true` if the core can safely sleep, `false` if it should continue running.
122124#[ inline]
123- pub fn core_sleep ( ) -> bool {
125+ pub fn try_sleep ( ) -> bool {
124126 CORE_HLT_STATE . read ( ) [ usize:: try_from ( core_id ( ) ) . unwrap ( ) ] . go_to_sleep ( )
125127}
126128
129+ /// Tries to wake up the core.
130+ /// Returns `true` if the core should be woken up via an interrupt, `false` if the core is already
131+ /// running.
127132#[ inline]
128- pub fn core_wake_up ( core_id : CoreId ) -> bool {
133+ pub fn try_wake_up ( core_id : CoreId ) -> bool {
129134 CORE_HLT_STATE . read ( ) [ usize:: try_from ( core_id) . unwrap ( ) ] . wake_up ( )
130135}
0 commit comments