aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/CHANGELOG.md2
-rw-r--r--embassy-executor/Cargo.toml2
-rw-r--r--embassy-executor/src/raw/mod.rs10
-rw-r--r--embassy-executor/src/raw/state_atomics.rs21
-rw-r--r--embassy-executor/src/raw/state_critical_section.rs15
5 files changed, 37 insertions, 13 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md
index 999c77a83..69c82653b 100644
--- a/embassy-executor/CHANGELOG.md
+++ b/embassy-executor/CHANGELOG.md
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10 10
11- Added new metadata API for tasks 11- Added new metadata API for tasks
12- Named main task when rtos-trace feature is enabled. 12- Named main task when rtos-trace feature is enabled.
13- Upgraded rtos-trace
14- Fixed performance regression on some ESP32 MCUs.
13 15
14## 0.9.0 - 2025-08-26 16## 0.9.0 - 2025-08-26
15 17
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index 79680ae74..dc423aba2 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -51,7 +51,7 @@ features = ["defmt", "arch-cortex-m", "executor-thread", "executor-interrupt"]
51[dependencies] 51[dependencies]
52defmt = { version = "1.0.1", optional = true } 52defmt = { version = "1.0.1", optional = true }
53log = { version = "0.4.14", optional = true } 53log = { version = "0.4.14", optional = true }
54rtos-trace = { version = "0.1.3", optional = true } 54rtos-trace = { version = "0.2", optional = true }
55 55
56embassy-executor-macros = { version = "0.7.0", path = "../embassy-executor-macros" } 56embassy-executor-macros = { version = "0.7.0", path = "../embassy-executor-macros" }
57embassy-time-driver = { version = "0.2.1", path = "../embassy-time-driver", optional = true } 57embassy-time-driver = { version = "0.2.1", path = "../embassy-time-driver", optional = true }
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index bdaa32951..4280c5750 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -12,8 +12,14 @@
12mod run_queue; 12mod run_queue;
13 13
14#[cfg_attr(all(cortex_m, target_has_atomic = "32"), 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(
16#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")] 16 all(not(cortex_m), any(target_has_atomic = "8", target_has_atomic = "32")),
17 path = "state_atomics.rs"
18)]
19#[cfg_attr(
20 not(any(target_has_atomic = "8", target_has_atomic = "32")),
21 path = "state_critical_section.rs"
22)]
17mod state; 23mod state;
18 24
19#[cfg(feature = "_any_trace")] 25#[cfg(feature = "_any_trace")]
diff --git a/embassy-executor/src/raw/state_atomics.rs b/embassy-executor/src/raw/state_atomics.rs
index e813548ae..6675875be 100644
--- a/embassy-executor/src/raw/state_atomics.rs
+++ b/embassy-executor/src/raw/state_atomics.rs
@@ -1,4 +1,15 @@
1use core::sync::atomic::{AtomicU8, Ordering}; 1// Prefer pointer-width atomic operations, as narrower ones may be slower.
2#[cfg(all(target_pointer_width = "32", target_has_atomic = "32"))]
3type AtomicState = core::sync::atomic::AtomicU32;
4#[cfg(not(all(target_pointer_width = "32", target_has_atomic = "32")))]
5type AtomicState = core::sync::atomic::AtomicU8;
6
7#[cfg(all(target_pointer_width = "32", target_has_atomic = "32"))]
8type StateBits = u32;
9#[cfg(not(all(target_pointer_width = "32", target_has_atomic = "32")))]
10type StateBits = u8;
11
12use core::sync::atomic::Ordering;
2 13
3#[derive(Clone, Copy)] 14#[derive(Clone, Copy)]
4pub(crate) struct Token(()); 15pub(crate) struct Token(());
@@ -11,18 +22,18 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
11} 22}
12 23
13/// Task is spawned (has a future) 24/// Task is spawned (has a future)
14pub(crate) const STATE_SPAWNED: u8 = 1 << 0; 25pub(crate) const STATE_SPAWNED: StateBits = 1 << 0;
15/// Task is in the executor run queue 26/// Task is in the executor run queue
16pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1; 27pub(crate) const STATE_RUN_QUEUED: StateBits = 1 << 1;
17 28
18pub(crate) struct State { 29pub(crate) struct State {
19 state: AtomicU8, 30 state: AtomicState,
20} 31}
21 32
22impl State { 33impl State {
23 pub const fn new() -> State { 34 pub const fn new() -> State {
24 Self { 35 Self {
25 state: AtomicU8::new(0), 36 state: AtomicState::new(0),
26 } 37 }
27 } 38 }
28 39
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs
index ec08f2f58..b69a6ac66 100644
--- a/embassy-executor/src/raw/state_critical_section.rs
+++ b/embassy-executor/src/raw/state_critical_section.rs
@@ -3,13 +3,18 @@ use core::cell::Cell;
3pub(crate) use critical_section::{with as locked, CriticalSection as Token}; 3pub(crate) use critical_section::{with as locked, CriticalSection as Token};
4use critical_section::{CriticalSection, Mutex}; 4use critical_section::{CriticalSection, Mutex};
5 5
6#[cfg(target_arch = "avr")]
7type StateBits = u8;
8#[cfg(not(target_arch = "avr"))]
9type StateBits = usize;
10
6/// Task is spawned (has a future) 11/// Task is spawned (has a future)
7pub(crate) const STATE_SPAWNED: u8 = 1 << 0; 12pub(crate) const STATE_SPAWNED: StateBits = 1 << 0;
8/// Task is in the executor run queue 13/// Task is in the executor run queue
9pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1; 14pub(crate) const STATE_RUN_QUEUED: StateBits = 1 << 1;
10 15
11pub(crate) struct State { 16pub(crate) struct State {
12 state: Mutex<Cell<u8>>, 17 state: Mutex<Cell<StateBits>>,
13} 18}
14 19
15impl State { 20impl State {
@@ -19,11 +24,11 @@ impl State {
19 } 24 }
20 } 25 }
21 26
22 fn update<R>(&self, f: impl FnOnce(&mut u8) -> R) -> R { 27 fn update<R>(&self, f: impl FnOnce(&mut StateBits) -> R) -> R {
23 critical_section::with(|cs| self.update_with_cs(cs, f)) 28 critical_section::with(|cs| self.update_with_cs(cs, f))
24 } 29 }
25 30
26 fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u8) -> R) -> R { 31 fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut StateBits) -> R) -> R {
27 let s = self.state.borrow(cs); 32 let s = self.state.borrow(cs);
28 let mut val = s.get(); 33 let mut val = s.get();
29 let r = f(&mut val); 34 let r = f(&mut val);