Struct esp_idf_hal::interrupt::asynch::IsrReactor
source · pub struct IsrReactor<const N: usize> { /* private fields */ }
Expand description
IsrReactor is a utility allowing Waker
instances to be awoken fron an ISR context.
General problem: In an interrupt, using Waker instances coming from generic executors is impossible, because these are not designed with an ISR-safety in mind.
Waking a waker means that its task would be scheduled on the executor queue, which might involve allocation, and/or synchronization primitives which are not safe to use from an ISR context.
Similarly, dropping a waker might also drop the executor task, resulting in a deallocation, which is also not safe in an ISR context.
These problems are alleviated by replacing direct waker.wake()
calls to WakerRunner::schedule(waker)
.
What IsrReactor::schedule
does is to push the waker into a bounded queue and then notify a hidden FreeRTOS task.
Once the FreeRTOS task gets awoken, it wakes all wakers scheduled on the bounded queue and empties the queue.
Implementations§
source§impl<const N: usize> IsrReactor<N>
impl<const N: usize> IsrReactor<N>
sourcepub const fn new(config: IsrReactorConfig) -> Self
pub const fn new(config: IsrReactorConfig) -> Self
Create a new IsrReactor
instance.
sourcepub fn is_started(&self) -> bool
pub fn is_started(&self) -> bool
Returns true
if the wake runner is started.
sourcepub fn start(&'static self) -> Result<bool, EspError>
pub fn start(&'static self) -> Result<bool, EspError>
Starts the wake runner. Returns false
if it had been already started.
sourcepub fn stop(&self) -> bool
pub fn stop(&self) -> bool
Stops the wake runner. Returns false
if it had been already stopped.
sourcepub fn schedule(&self, waker: Waker)
pub fn schedule(&self, waker: Waker)
Schedules a waker to be awoken by the hidden FreeRTOS task running in the background.
If not called from within an ISR context, calls waker.wake()
directly instead of scheduling the waker.
NOTE: If the wake runner is not started yet, scheduling fron an ISR content would fail silently.
This and only this method is safe to call from an ISR context.