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 trait Model {
fn signal();
}
pub struct WfeModel;
impl Model for WfeModel {
fn signal() {
cortex_m::asm::sev()
}
}
pub struct Executor<M, A: Alarm> {
pub struct Executor<A: Alarm> {
inner: se::Executor,
alarm: A,
timer: time::TimerService,
_phantom: PhantomData<M>,
}
impl<M: Model, A: Alarm> Executor<M, A> {
pub fn new(alarm: A) -> Self {
alarm.set_callback(M::signal);
impl<A: Alarm> Executor<A> {
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<M: Model, A: Alarm> Executor<M, A> {
/// 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<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()
}
}
}