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>
impl<Data> MultiCoreSignal<Data>
Sourcepub fn signal(&self, data: Data)
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).
Sourcepub fn wait(&self) -> _MultiCoreSignal<'_, Data> ⓘ
pub fn wait(&self) -> _MultiCoreSignal<'_, Data> ⓘ
Returns a future that resolves when data is signaled.