From 5c7a666938022eeae92ec9a0b3b07c31953a6243 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sat, 7 Oct 2023 08:58:10 +0000 Subject: [PATCH] Rename WakeRunner to IsrReactor --- CHANGELOG.md | 2 +- src/interrupt.rs | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b82738904..eb78d5d08f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * New driver: continuous ADC * New driver: snapshot ADC, implementing the new ESP-IDF 5.0+ snapshot ADC API * Async support in the following drivers: SPI, I2S, continuous ADC, CAN (via an `AsyncCanDriver` wrapper), UART (via an `AsyncUartDriver` wrapper) -* All async drivers can now work out of the box with any executor (`edge-executor` no longer a necessity) via a new ISR-to-task bridge (`esp_idf_hal::interrupt::asynch::WakeRunner`) +* All async drivers can now work out of the box with any executor (`edge-executor` no longer a necessity) via a new ISR-to-task bridge (`esp_idf_hal::interrupt::asynch::IsrReactor`) * CAN driver: support for pulling alerts in blocking and async mode * UART driver: support for pulling UART events * `task` and `interrupt` modules: new submodule in each - `asynch` - featuring a signal/notification-like synchronization primitive diff --git a/src/interrupt.rs b/src/interrupt.rs index 0409b3f1878..ae700fae11c 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs @@ -329,7 +329,7 @@ pub mod asynch { /// You should use no more than 64 tasks with it. /// /// `*IsrNotification` instances use this wake runner when they are triggered from an ISR context. - pub static HAL_WAKE_RUNNER: WakeRunner<64> = WakeRunner::new(WakeRunnerConfig::new()); + pub static HAL_ISR_REACTOR: IsrReactor<64> = IsrReactor::new(WakeRunnerConfig::new()); /// Wake runner configuration #[derive(Clone, Debug)] @@ -343,7 +343,7 @@ pub mod asynch { impl WakeRunnerConfig { pub const fn new() -> Self { Self { - task_name: unsafe { CStr::from_bytes_with_nul_unchecked(b"WakeRunner\0") }, + task_name: unsafe { CStr::from_bytes_with_nul_unchecked(b"IsrReactor\0") }, task_stack_size: 3084, task_priority: 11, task_pin_to_core: None, @@ -357,7 +357,7 @@ pub mod asynch { } } - /// WakeRunner is a utility allowing `Waker` instances to be awoken fron an ISR context. + /// 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, @@ -369,10 +369,10 @@ pub mod asynch { /// 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::wake(waker)`. - /// What `WakeRunner::wake` does is to push the waker into a bounded queue and then notify a hidden FreeRTOS task. + /// 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. - pub struct WakeRunner { + pub struct IsrReactor { wakers_cs: IsrCriticalSection, wakers: UnsafeCell>, task_cs: CriticalSection, @@ -380,8 +380,8 @@ pub mod asynch { task_config: WakeRunnerConfig, } - impl WakeRunner { - /// Create a new `WakeRunner` instance. + impl IsrReactor { + /// Create a new `IsrReactor` instance. pub const fn new(config: WakeRunnerConfig) -> Self { Self { wakers_cs: IsrCriticalSection::new(), @@ -415,7 +415,7 @@ pub mod asynch { self.task.store(task as _, Ordering::SeqCst); - info!("WakeRunner {:?} started.", self.task_config.task_name); + info!("IsrReactor {:?} started.", self.task_config.task_name); Ok(true) } else { @@ -434,7 +434,7 @@ pub mod asynch { crate::task::destroy(task as _); } - info!("WakeRunner {:?} stopped.", self.task_config.task_name); + info!("IsrReactor {:?} stopped.", self.task_config.task_name); true } else { @@ -455,7 +455,7 @@ pub mod asynch { if let Some(earlier_waker) = earlier_waker { *earlier_waker = waker; } else if wakers.push_back(waker).is_err() { - panic!("WakeRunner queue overflow"); + panic!("IsrReactor queue overflow"); } let task = self.task.load(Ordering::SeqCst); @@ -503,20 +503,20 @@ pub mod asynch { extern "C" fn task_run(ctx: *mut c_void) { let this = - unsafe { (ctx as *mut WakeRunner as *const WakeRunner).as_ref() }.unwrap(); + unsafe { (ctx as *mut IsrReactor as *const IsrReactor).as_ref() }.unwrap(); this.run(); } } - impl Drop for WakeRunner { + impl Drop for IsrReactor { fn drop(&mut self) { self.stop(); } } - unsafe impl Send for WakeRunner {} - unsafe impl Sync for WakeRunner {} + unsafe impl Send for IsrReactor {} + unsafe impl Sync for IsrReactor {} /// Single-slot lock-free signaling primitive supporting signalling with a `u32` bit-set. /// A variation of the `Notification` HAL primitive which is however safe to be notified from an ISR context. @@ -531,16 +531,16 @@ pub mod asynch { /// but for synchronization between an asynchronous task, and another one, which might be blocking or asynchronous. pub struct IsrNotification { inner: Notification, - runner: &'static WakeRunner, + reactor: &'static IsrReactor, } impl IsrNotification { /// Creates a new `IsrNotification`. /// This method is safe to call from an ISR context, yet such use cases should not normally occur in practice. - pub const fn new(runner: &'static WakeRunner) -> Self { + pub const fn new(reactor: &'static IsrReactor) -> Self { Self { inner: Notification::new(), - runner, + reactor, } } @@ -556,7 +556,7 @@ pub mod asynch { /// Returns `true` if there was a registered waker which got awoken. pub fn notify(&self, bits: NonZeroU32) -> bool { if let Some(waker) = self.inner.notify_waker(bits) { - self.runner.schedule(waker); + self.reactor.schedule(waker); true } else { @@ -574,7 +574,7 @@ pub mod asynch { /// This method is NOT safe to call from an ISR context. #[allow(unused)] pub fn wait(&self) -> impl Future + '_ { - self.runner.start().unwrap(); + self.reactor.start().unwrap(); self.inner.wait() } @@ -582,7 +582,7 @@ pub mod asynch { /// Non-blocking method to check whether this notification has been notified. /// This method is NOT safe to call from an ISR context. pub fn poll_wait(&self, cx: &Context<'_>) -> Poll { - self.runner.start().unwrap(); + self.reactor.start().unwrap(); self.inner.poll_wait(cx) } @@ -626,7 +626,7 @@ pub mod asynch { /// Returns `true` if there was a registered waker which got awoken. pub fn notify(&self, bits: NonZeroU32) -> bool { if let Some(waker) = self.inner.notify_waker(bits) { - HAL_WAKE_RUNNER.schedule(waker); + HAL_ISR_REACTOR.schedule(waker); true } else { @@ -644,7 +644,7 @@ pub mod asynch { /// This method is NOT safe to call from an ISR context. #[allow(unused)] pub fn wait(&self) -> impl Future + '_ { - HAL_WAKE_RUNNER.start().unwrap(); + HAL_ISR_REACTOR.start().unwrap(); self.inner.wait() } @@ -652,7 +652,7 @@ pub mod asynch { /// Non-blocking method to check whether this notification has been notified. /// This method is NOT safe to call from an ISR context. pub fn poll_wait(&self, cx: &Context<'_>) -> Poll { - HAL_WAKE_RUNNER.start().unwrap(); + HAL_ISR_REACTOR.start().unwrap(); self.inner.poll_wait(cx) }