executor: Make state implementations and their conditions match

Use u8 for state_atomics and state_critical_section since that
is all that is needed. Change arm condition to "32" since that is what
is used and required.
This commit is contained in:
Johan Anderholm 2023-12-30 11:54:16 +01:00
parent 94f9b27074
commit 0f9a7a057f
3 changed files with 11 additions and 11 deletions

View File

@ -11,7 +11,7 @@
#[cfg_attr(not(target_has_atomic = "ptr"), path = "run_queue_critical_section.rs")]
mod run_queue;
#[cfg_attr(all(cortex_m, target_has_atomic = "8"), path = "state_atomics_arm.rs")]
#[cfg_attr(all(cortex_m, target_has_atomic = "32"), path = "state_atomics_arm.rs")]
#[cfg_attr(all(not(cortex_m), target_has_atomic = "8"), path = "state_atomics.rs")]
#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")]
mod state;

View File

@ -1,4 +1,4 @@
use core::sync::atomic::{AtomicU32, Ordering};
use core::sync::atomic::{AtomicU8, Ordering};
#[derive(Clone, Copy)]
pub(crate) struct Token(());
@ -11,18 +11,18 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
}
/// Task is spawned (has a future)
pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
pub(crate) const STATE_SPAWNED: u8 = 1 << 0;
/// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1;
pub(crate) struct State {
state: AtomicU32,
state: AtomicU8,
}
impl State {
pub const fn new() -> State {
Self {
state: AtomicU32::new(0),
state: AtomicU8::new(0),
}
}

View File

@ -4,12 +4,12 @@ pub(crate) use critical_section::{with as locked, CriticalSection as Token};
use critical_section::{CriticalSection, Mutex};
/// Task is spawned (has a future)
pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
pub(crate) const STATE_SPAWNED: u8 = 1 << 0;
/// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1;
pub(crate) struct State {
state: Mutex<Cell<u32>>,
state: Mutex<Cell<u8>>,
}
impl State {
@ -19,11 +19,11 @@ impl State {
}
}
fn update<R>(&self, f: impl FnOnce(&mut u32) -> R) -> R {
fn update<R>(&self, f: impl FnOnce(&mut u8) -> R) -> R {
critical_section::with(|cs| self.update_with_cs(cs, f))
}
fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u32) -> R) -> R {
fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u8) -> R) -> R {
let s = self.state.borrow(cs);
let mut val = s.get();
let r = f(&mut val);