aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-06-01 12:16:50 +0000
committerGitHub <[email protected]>2025-06-01 12:16:50 +0000
commitad5a14fe850190b3052487f87a579eaf7ea65ec5 (patch)
tree61eecea8f96ec733c01dfb2fe3df31cb6be593b0 /embassy-executor/src
parentfc4139146f27f0b5b53dc0de40db910ecce461c2 (diff)
parent0f9a7a057fb7dfb2358acec9068fece82c7c7a89 (diff)
Merge pull request #4244 from janderholm/master
executor: Make state implementations and their conditions match
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/mod.rs2
-rw-r--r--embassy-executor/src/raw/state_atomics.rs10
-rw-r--r--embassy-executor/src/raw/state_critical_section.rs10
3 files changed, 11 insertions, 11 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index e7a27035a..913da2e25 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -11,7 +11,7 @@
11#[cfg_attr(not(target_has_atomic = "ptr"), path = "run_queue_critical_section.rs")] 11#[cfg_attr(not(target_has_atomic = "ptr"), path = "run_queue_critical_section.rs")]
12mod run_queue; 12mod run_queue;
13 13
14#[cfg_attr(all(cortex_m, target_has_atomic = "8"), path = "state_atomics_arm.rs")] 14#[cfg_attr(all(cortex_m, target_has_atomic = "32"), path = "state_atomics_arm.rs")]
15#[cfg_attr(all(not(cortex_m), target_has_atomic = "8"), path = "state_atomics.rs")] 15#[cfg_attr(all(not(cortex_m), target_has_atomic = "8"), path = "state_atomics.rs")]
16#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")] 16#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")]
17mod state; 17mod state;
diff --git a/embassy-executor/src/raw/state_atomics.rs b/embassy-executor/src/raw/state_atomics.rs
index b6576bfc2..e813548ae 100644
--- a/embassy-executor/src/raw/state_atomics.rs
+++ b/embassy-executor/src/raw/state_atomics.rs
@@ -1,4 +1,4 @@
1use core::sync::atomic::{AtomicU32, Ordering}; 1use core::sync::atomic::{AtomicU8, Ordering};
2 2
3#[derive(Clone, Copy)] 3#[derive(Clone, Copy)]
4pub(crate) struct Token(()); 4pub(crate) struct Token(());
@@ -11,18 +11,18 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
11} 11}
12 12
13/// Task is spawned (has a future) 13/// Task is spawned (has a future)
14pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 14pub(crate) const STATE_SPAWNED: u8 = 1 << 0;
15/// Task is in the executor run queue 15/// Task is in the executor run queue
16pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 16pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1;
17 17
18pub(crate) struct State { 18pub(crate) struct State {
19 state: AtomicU32, 19 state: AtomicU8,
20} 20}
21 21
22impl State { 22impl State {
23 pub const fn new() -> State { 23 pub const fn new() -> State {
24 Self { 24 Self {
25 state: AtomicU32::new(0), 25 state: AtomicU8::new(0),
26 } 26 }
27 } 27 }
28 28
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs
index 6b627ff79..ec08f2f58 100644
--- a/embassy-executor/src/raw/state_critical_section.rs
+++ b/embassy-executor/src/raw/state_critical_section.rs
@@ -4,12 +4,12 @@ pub(crate) use critical_section::{with as locked, CriticalSection as Token};
4use critical_section::{CriticalSection, Mutex}; 4use critical_section::{CriticalSection, Mutex};
5 5
6/// Task is spawned (has a future) 6/// Task is spawned (has a future)
7pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 7pub(crate) const STATE_SPAWNED: u8 = 1 << 0;
8/// Task is in the executor run queue 8/// Task is in the executor run queue
9pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 9pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1;
10 10
11pub(crate) struct State { 11pub(crate) struct State {
12 state: Mutex<Cell<u32>>, 12 state: Mutex<Cell<u8>>,
13} 13}
14 14
15impl State { 15impl State {
@@ -19,11 +19,11 @@ impl State {
19 } 19 }
20 } 20 }
21 21
22 fn update<R>(&self, f: impl FnOnce(&mut u32) -> R) -> R { 22 fn update<R>(&self, f: impl FnOnce(&mut u8) -> R) -> R {
23 critical_section::with(|cs| self.update_with_cs(cs, f)) 23 critical_section::with(|cs| self.update_with_cs(cs, f))
24 } 24 }
25 25
26 fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u32) -> R) -> R { 26 fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u8) -> R) -> R {
27 let s = self.state.borrow(cs); 27 let s = self.state.borrow(cs);
28 let mut val = s.get(); 28 let mut val = s.get();
29 let r = f(&mut val); 29 let r = f(&mut val);