MultiCoreSignal

Struct MultiCoreSignal 

Source
pub struct MultiCoreSignal<Data> { /* private fields */ }
Expand description

A cross-task/cross-core synchronization primitive for passing data between producers and consumers.

MultiCoreSignal acts as a high-performance, single-slot mailbox. It allows one task (or core) to notify another task that data is ready. It uses an AtomicBool for fast “dirty” checks before acquiring a heavier Mutex lock, minimizing contention.

§Design

This signal is reset-on-read. When the consumer .awaits the signal and successfully receives the data, the internal state is cleared, and subsequent polls will return Poll::Pending until the producer calls signal() again.

§Examples

static RENDER_SIGNAL: MultiCoreSignal<u64> = MultiCoreSignal::new();

/// Producer: Runs physics calculations and notifies the renderer
async fn physics_task() {
    let mut frame_count = 0;
    loop {
        do_physics_calc();
        frame_count += 1;

        // Update the signal with the new frame index
        RENDER_SIGNAL.signal(frame_count);

        Yield.await;
    }
}

/// Consumer: Waits for the signal and renders the frame
async fn render_task() {
    loop {
        // Execution suspends here until RENDER_SIGNAL.signal() is called
        let frame = RENDER_SIGNAL.wait().await;

        draw_frame(frame);

        // Yield once to allow other tasks to process before next wait
        Yield.await;
    }
}

Implementations§

Source§

impl<Data> MultiCoreSignal<Data>

Source

pub const fn new() -> Self

Creates a new, empty MultiCoreSignal.

Source

pub fn signal(&self, data: Data)

Deposits data into the signal and notifies any waiting consumers.

If data already exists in the slot and hasn’t been read yet, it will be overwritten (Last-Write-Wins).

Source

pub fn wait(&self) -> _MultiCoreSignal<'_, Data>

Returns a future that resolves when data is signaled.

Source

pub fn reset(&self)

Manually clears the signal data and resets the notification flag.

Trait Implementations§

Source§

impl<Data: Debug> Debug for MultiCoreSignal<Data>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Data> !Freeze for MultiCoreSignal<Data>

§

impl<Data> !RefUnwindSafe for MultiCoreSignal<Data>

§

impl<Data> Send for MultiCoreSignal<Data>
where Data: Send,

§

impl<Data> Sync for MultiCoreSignal<Data>
where Data: Send,

§

impl<Data> Unpin for MultiCoreSignal<Data>
where Data: Unpin,

§

impl<Data> UnwindSafe for MultiCoreSignal<Data>
where Data: UnwindSafe,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

type Error = Infallible

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.