Remove executor model (it's not a nice enough abstraction).

This commit is contained in:
Dario Nieuwenhuis 2020-09-25 23:42:49 +02:00
parent 19a89b5c14
commit f88f233e39
2 changed files with 13 additions and 35 deletions

View File

@ -6,33 +6,19 @@ use crate::time::Alarm;
pub use se::{task, SpawnError, SpawnToken}; pub use se::{task, SpawnError, SpawnToken};
pub trait Model { pub struct Executor<A: Alarm> {
fn signal();
}
pub struct WfeModel;
impl Model for WfeModel {
fn signal() {
cortex_m::asm::sev()
}
}
pub struct Executor<M, A: Alarm> {
inner: se::Executor, inner: se::Executor,
alarm: A, alarm: A,
timer: time::TimerService, timer: time::TimerService,
_phantom: PhantomData<M>,
} }
impl<M: Model, A: Alarm> Executor<M, A> { impl<A: Alarm> Executor<A> {
pub fn new(alarm: A) -> Self { pub fn new(alarm: A, signal_fn: fn()) -> Self {
alarm.set_callback(M::signal); alarm.set_callback(signal_fn);
Self { Self {
inner: se::Executor::new(M::signal), inner: se::Executor::new(signal_fn),
alarm, alarm,
timer: time::TimerService::new(time::IntrusiveClock), timer: time::TimerService::new(time::IntrusiveClock),
_phantom: PhantomData,
} }
} }
@ -46,7 +32,7 @@ impl<M: Model, A: Alarm> Executor<M, A> {
/// Runs the executor until the queue is empty. /// Runs the executor until the queue is empty.
/// ///
/// safety: can only be called from the executor thread /// 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, || { time::with_timer_service(&self.timer, || {
self.timer.check_expirations(); self.timer.check_expirations();
self.inner.run(); self.inner.run();
@ -60,14 +46,3 @@ impl<M: Model, A: Alarm> Executor<M, A> {
}) })
} }
} }
impl<A: Alarm> Executor<WfeModel, A> {
/// 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()
}
}
}

View File

@ -8,7 +8,7 @@ use example_common::*;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embassy::executor::{task, Executor, WfeModel}; use embassy::executor::{task, Executor};
use embassy::time::{Clock, Duration, Timer}; use embassy::time::{Clock, Duration, Timer};
use embassy_nrf::pac; use embassy_nrf::pac;
use embassy_nrf::rtc; use embassy_nrf::rtc;
@ -31,7 +31,7 @@ async fn run2() {
} }
static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit(); static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit();
static mut EXECUTOR: MaybeUninit<Executor<WfeModel, rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit(); static mut EXECUTOR: MaybeUninit<Executor<rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -55,7 +55,7 @@ fn main() -> ! {
let executor: &'static _ = unsafe { let executor: &'static _ = unsafe {
let ptr = EXECUTOR.as_mut_ptr(); let ptr = EXECUTOR.as_mut_ptr();
ptr.write(Executor::new(rtc.alarm0())); ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev));
&*ptr &*ptr
}; };
@ -63,6 +63,9 @@ fn main() -> ! {
executor.spawn(run1()).dewrap(); executor.spawn(run1()).dewrap();
executor.spawn(run2()).dewrap(); executor.spawn(run2()).dewrap();
executor.run() loop {
executor.run();
cortex_m::asm::wfe();
}
} }
} }