From f88f233e39f1edef04a51b888a47b9e231fc228f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 25 Sep 2020 23:42:49 +0200 Subject: [PATCH] Remove executor model (it's not a nice enough abstraction). --- embassy/src/executor.rs | 37 ++++++----------------------------- examples/src/bin/rtc_async.rs | 11 +++++++---- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/embassy/src/executor.rs b/embassy/src/executor.rs index 2c7cc5786..d42a19b9a 100644 --- a/embassy/src/executor.rs +++ b/embassy/src/executor.rs @@ -6,33 +6,19 @@ use crate::time::Alarm; pub use se::{task, SpawnError, SpawnToken}; -pub trait Model { - fn signal(); -} - -pub struct WfeModel; - -impl Model for WfeModel { - fn signal() { - cortex_m::asm::sev() - } -} - -pub struct Executor { +pub struct Executor { inner: se::Executor, alarm: A, timer: time::TimerService, - _phantom: PhantomData, } -impl Executor { - pub fn new(alarm: A) -> Self { - alarm.set_callback(M::signal); +impl Executor { + pub fn new(alarm: A, signal_fn: fn()) -> Self { + alarm.set_callback(signal_fn); Self { - inner: se::Executor::new(M::signal), + inner: se::Executor::new(signal_fn), alarm, timer: time::TimerService::new(time::IntrusiveClock), - _phantom: PhantomData, } } @@ -46,7 +32,7 @@ impl Executor { /// Runs the executor until the queue is empty. /// /// safety: can only be called from the executor thread - pub unsafe fn run_once(&'static self) { + pub unsafe fn run(&'static self) { time::with_timer_service(&self.timer, || { self.timer.check_expirations(); self.inner.run(); @@ -60,14 +46,3 @@ impl Executor { }) } } - -impl Executor { - /// Runs the executor forever - /// safety: can only be called from the executor thread - pub unsafe fn run(&'static self) -> ! { - loop { - self.run_once(); - cortex_m::asm::wfe() - } - } -} diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs index a4149ef1e..30b181a93 100644 --- a/examples/src/bin/rtc_async.rs +++ b/examples/src/bin/rtc_async.rs @@ -8,7 +8,7 @@ use example_common::*; use core::mem::MaybeUninit; use cortex_m_rt::entry; -use embassy::executor::{task, Executor, WfeModel}; +use embassy::executor::{task, Executor}; use embassy::time::{Clock, Duration, Timer}; use embassy_nrf::pac; use embassy_nrf::rtc; @@ -31,7 +31,7 @@ async fn run2() { } static mut RTC: MaybeUninit> = MaybeUninit::uninit(); -static mut EXECUTOR: MaybeUninit>> = MaybeUninit::uninit(); +static mut EXECUTOR: MaybeUninit>> = MaybeUninit::uninit(); #[entry] fn main() -> ! { @@ -55,7 +55,7 @@ fn main() -> ! { let executor: &'static _ = unsafe { let ptr = EXECUTOR.as_mut_ptr(); - ptr.write(Executor::new(rtc.alarm0())); + ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev)); &*ptr }; @@ -63,6 +63,9 @@ fn main() -> ! { executor.spawn(run1()).dewrap(); executor.spawn(run2()).dewrap(); - executor.run() + loop { + executor.run(); + cortex_m::asm::wfe(); + } } }