embassy-sync

Crates

git

Versions

default

Flavors

Skip to main content

AtomicWaker

Struct AtomicWaker 

Source
pub struct AtomicWaker { /* private fields */ }
Expand description

Utility struct to register and wake a waker.

Single-slot waker coordinated by an atomic state machine. Unlike CriticalSectionWaker, wake() does not enter a critical section, which avoids unnecessary jitter on higher-priority interrupts and improves wake latency for time-critical async drivers.

If a waker is registered, registering a different waker replaces the previous one and wakes it, giving the displaced task a chance to re-register itself. This matches the semantics of WakerRegistration; note that GenericAtomicWaker and CriticalSectionWaker instead replace the previous waker without waking it.

Intended to wake a single task from an interrupt handler.

On targets without 32-bit atomic CAS support (e.g. Xtensa S2, AVR, RV32I), AtomicWaker is a type alias for CriticalSectionWaker, since the lockless state machine relies on compare_exchange/swap/fetch_or.

Implementations§

Source§

impl AtomicWaker

Source

pub const fn new() -> Self

Create a new AtomicWaker.

Source

pub fn register(&self, waker: &Waker)

Register a waker.

If a different waker was previously registered, it is replaced and woken so the displaced task can re-register itself if it is still interested. This matches WakerRegistration::register.

If a wake call is in flight when this is called, the supplied waker is woken directly to schedule a re-poll.

Source

pub fn wake(&self)

Wake the registered waker, if any.

A clone of the stored waker is woken after the state is released, so the stored waker remains registered, matching the semantics of CriticalSectionWaker.

Trait Implementations§

Source§

impl Default for AtomicWaker

Available on target_has_atomic=32 only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for AtomicWaker

Available on target_has_atomic=32 only.
Source§

impl Sync for AtomicWaker

Available on target_has_atomic=32 only.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.