pub trait AtomicState {
type State: Copy;
// Required methods
fn peek(&self) -> Self::State;
fn load(&self) -> Self::State;
fn switch_to_desired(
&self,
desired_state: Self::State,
) -> SwitchAtomicStateOk<Self::State>;
fn switch_from_expected_to_desired(
&self,
expected_state: Self::State,
desired_state: Self::State,
) -> SwitchAtomicStateResult<Self::State>;
}Expand description
Atomic operations for state transitions
Needed for implementing state machines with atomic state transitions.
Required Associated Types§
Required Methods§
Sourcefn load(&self) -> Self::State
fn load(&self) -> Self::State
Load the current state
Uses the same memory ordering semantics as when switching the state.
Sourcefn switch_to_desired(
&self,
desired_state: Self::State,
) -> SwitchAtomicStateOk<Self::State>
fn switch_to_desired( &self, desired_state: Self::State, ) -> SwitchAtomicStateOk<Self::State>
Switch to the desired state unconditionally
Replaces the current state with the desired state independent of the current state and returns the previous state.
Sourcefn switch_from_expected_to_desired(
&self,
expected_state: Self::State,
desired_state: Self::State,
) -> SwitchAtomicStateResult<Self::State>
fn switch_from_expected_to_desired( &self, expected_state: Self::State, desired_state: Self::State, ) -> SwitchAtomicStateResult<Self::State>
Switch to the desired state conditionally
Replaces the current state with the desired state if it equals the given expected state and returns the previous state. Otherwise returns the unmodified current state.