aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authoreverdrone <[email protected]>2025-11-11 15:48:56 +0100
committereverdrone <[email protected]>2025-11-11 15:48:56 +0100
commitcede7216861a82b0db55f5a88afb3acf2ace6c4b (patch)
treed92fb578897c77f51317318c5b180931b7b25c63 /embassy-executor
parentcf55b39f9a54cf3ed01f52c0565a36a444174235 (diff)
parent3d1f09597335d3681699ba09a77da4b39ed984fd (diff)
Merge branch main into n6
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/CHANGELOG.md2
-rw-r--r--embassy-executor/Cargo.toml19
-rw-r--r--embassy-executor/build.rs5
-rw-r--r--embassy-executor/src/arch/avr.rs4
-rw-r--r--embassy-executor/src/arch/cortex_ar.rs11
-rw-r--r--embassy-executor/src/arch/cortex_m.rs4
-rw-r--r--embassy-executor/src/arch/riscv32.rs4
-rw-r--r--embassy-executor/src/arch/spin.rs4
-rw-r--r--embassy-executor/src/arch/std.rs4
-rw-r--r--embassy-executor/src/arch/wasm.rs4
-rw-r--r--embassy-executor/src/lib.rs1
-rw-r--r--embassy-executor/src/metadata.rs2
-rw-r--r--embassy-executor/src/raw/mod.rs8
-rw-r--r--embassy-executor/src/raw/run_queue.rs4
-rw-r--r--embassy-executor/src/raw/state_atomics_arm.rs2
-rw-r--r--embassy-executor/src/raw/state_critical_section.rs2
-rw-r--r--embassy-executor/src/raw/trace.rs8
-rw-r--r--embassy-executor/src/raw/waker.rs6
-rw-r--r--embassy-executor/src/raw/waker_turbo.rs4
-rw-r--r--embassy-executor/src/spawner.rs12
-rw-r--r--embassy-executor/tests/test.rs6
-rw-r--r--embassy-executor/tests/ui/nonstatic_struct_elided.stderr12
-rw-r--r--embassy-executor/tests/ui/spawn_nonsend.rs2
-rw-r--r--embassy-executor/tests/ui/spawn_nonsend.stderr22
-rw-r--r--embassy-executor/tests/ui/task_safety_attribute.rs2
-rw-r--r--embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr2
26 files changed, 86 insertions, 70 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md
index 6f079a11a..5fbb8cf13 100644
--- a/embassy-executor/CHANGELOG.md
+++ b/embassy-executor/CHANGELOG.md
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13- Upgraded rtos-trace 13- Upgraded rtos-trace
14- Added optional "highest priority" scheduling 14- Added optional "highest priority" scheduling
15- Added optional "earliest deadline first" EDF scheduling 15- Added optional "earliest deadline first" EDF scheduling
16- Migrate `cortex-ar` to `aarch32-cpu`. The feature name `arch-cortex-ar` remains the same and
17 legacy ARM architectures are not supported.
16 18
17## 0.9.1 - 2025-08-31 19## 0.9.1 - 2025-08-31
18 20
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index f6dce5c0e..d3e5b241a 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "embassy-executor" 2name = "embassy-executor"
3version = "0.9.1" 3version = "0.9.1"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6description = "async/await executor designed for embedded usage" 6description = "async/await executor designed for embedded usage"
7repository = "https://github.com/embassy-rs/embassy" 7repository = "https://github.com/embassy-rs/embassy"
@@ -30,11 +30,15 @@ build = [
30 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "embassy-time-driver", "scheduler-deadline"]}, 30 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "embassy-time-driver", "scheduler-deadline"]},
31 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "scheduler-priority", "scheduler-deadline"]}, 31 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "scheduler-priority", "scheduler-deadline"]},
32 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "scheduler-deadline"]}, 32 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "scheduler-deadline"]},
33 {target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-interrupt", "executor-thread", "embassy-time-driver", "scheduler-priority", "scheduler-deadline", "trace"]},
34 {target = "thumbv7em-none-eabi", features = ["arch-spin"]},
35 {target = "thumbv7em-none-eabi", features = ["arch-spin", "scheduler-deadline"]},
33 {target = "armv7a-none-eabi", features = ["arch-cortex-ar", "executor-thread"]}, 36 {target = "armv7a-none-eabi", features = ["arch-cortex-ar", "executor-thread"]},
34 {target = "armv7r-none-eabi", features = ["arch-cortex-ar", "executor-thread"]}, 37 {target = "armv7r-none-eabi", features = ["arch-cortex-ar", "executor-thread"]},
35 {target = "armv7r-none-eabihf", features = ["arch-cortex-ar", "executor-thread"]}, 38 {target = "armv7r-none-eabihf", features = ["arch-cortex-ar", "executor-thread"]},
36 {target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32"]}, 39 {target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32"]},
37 {target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32", "executor-thread"]}, 40 {target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32", "executor-thread"]},
41 {target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32", "executor-thread", "trace"]},
38 # Nightly builds 42 # Nightly builds
39 {group = "nightly", target = "thumbv7em-none-eabi", features = ["nightly"]}, 43 {group = "nightly", target = "thumbv7em-none-eabi", features = ["nightly"]},
40 {group = "nightly", target = "thumbv7em-none-eabi", features = ["nightly", "log"]}, 44 {group = "nightly", target = "thumbv7em-none-eabi", features = ["nightly", "log"]},
@@ -98,7 +102,7 @@ portable-atomic = { version = "1.5", optional = true }
98cortex-m = { version = "0.7.6", optional = true } 102cortex-m = { version = "0.7.6", optional = true }
99 103
100# arch-cortex-ar dependencies 104# arch-cortex-ar dependencies
101cortex-ar = { version = "0.2", optional = true } 105aarch32-cpu = { version = "0.1", optional = true }
102 106
103# arch-wasm dependencies 107# arch-wasm dependencies
104wasm-bindgen = { version = "0.2.82", optional = true } 108wasm-bindgen = { version = "0.2.82", optional = true }
@@ -123,6 +127,12 @@ rustversion = "1.0.21"
123## Enable nightly-only features 127## Enable nightly-only features
124nightly = ["embassy-executor-macros/nightly"] 128nightly = ["embassy-executor-macros/nightly"]
125 129
130## Enable defmt logging
131defmt = ["dep:defmt"]
132
133## Enable log logging
134log = ["dep:log"]
135
126# Enables turbo wakers, which requires patching core. Not surfaced in the docs by default due to 136# Enables turbo wakers, which requires patching core. Not surfaced in the docs by default due to
127# being an complicated advanced and undocumented feature. 137# being an complicated advanced and undocumented feature.
128# See: https://github.com/embassy-rs/embassy/pull/1263 138# See: https://github.com/embassy-rs/embassy/pull/1263
@@ -135,7 +145,7 @@ arch-std = ["_arch"]
135## Cortex-M 145## Cortex-M
136arch-cortex-m = ["_arch", "dep:cortex-m"] 146arch-cortex-m = ["_arch", "dep:cortex-m"]
137## Cortex-A/R 147## Cortex-A/R
138arch-cortex-ar = ["_arch", "dep:cortex-ar"] 148arch-cortex-ar = ["_arch", "dep:aarch32-cpu", "dep:arm-targets"]
139## RISC-V 32 149## RISC-V 32
140arch-riscv32 = ["_arch"] 150arch-riscv32 = ["_arch"]
141## WASM 151## WASM
@@ -172,3 +182,6 @@ scheduler-priority = []
172## Enable the embassy_time_driver dependency. 182## Enable the embassy_time_driver dependency.
173## This can unlock extra APIs, for example for the `sheduler-deadline` 183## This can unlock extra APIs, for example for the `sheduler-deadline`
174embassy-time-driver = ["dep:embassy-time-driver"] 184embassy-time-driver = ["dep:embassy-time-driver"]
185
186[build-dependencies]
187arm-targets = { version = "0.4", optional = true }
diff --git a/embassy-executor/build.rs b/embassy-executor/build.rs
index 37becde3e..36e23a632 100644
--- a/embassy-executor/build.rs
+++ b/embassy-executor/build.rs
@@ -4,4 +4,9 @@ mod common;
4fn main() { 4fn main() {
5 let mut rustc_cfgs = common::CfgSet::new(); 5 let mut rustc_cfgs = common::CfgSet::new();
6 common::set_target_cfgs(&mut rustc_cfgs); 6 common::set_target_cfgs(&mut rustc_cfgs);
7
8 // This is used to exclude legacy architecture support. The raw executor needs to be used for
9 // those architectures because SEV/WFE are not supported.
10 #[cfg(feature = "arch-cortex-ar")]
11 arm_targets::process();
7} 12}
diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs
index 70085d04d..a841afe15 100644
--- a/embassy-executor/src/arch/avr.rs
+++ b/embassy-executor/src/arch/avr.rs
@@ -10,11 +10,11 @@ mod thread {
10 pub use embassy_executor_macros::main_avr as main; 10 pub use embassy_executor_macros::main_avr as main;
11 use portable_atomic::{AtomicBool, Ordering}; 11 use portable_atomic::{AtomicBool, Ordering};
12 12
13 use crate::{raw, Spawner}; 13 use crate::{Spawner, raw};
14 14
15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); 15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
16 16
17 #[export_name = "__pender"] 17 #[unsafe(export_name = "__pender")]
18 fn __pender(_context: *mut ()) { 18 fn __pender(_context: *mut ()) {
19 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); 19 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
20 } 20 }
diff --git a/embassy-executor/src/arch/cortex_ar.rs b/embassy-executor/src/arch/cortex_ar.rs
index f9e2f3f7c..ce572738a 100644
--- a/embassy-executor/src/arch/cortex_ar.rs
+++ b/embassy-executor/src/arch/cortex_ar.rs
@@ -1,7 +1,10 @@
1#[cfg(arm_profile = "legacy")]
2compile_error!("`arch-cortex-ar` does not support the legacy ARM profile, WFE/SEV are not available.");
3
1#[cfg(feature = "executor-interrupt")] 4#[cfg(feature = "executor-interrupt")]
2compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`."); 5compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`.");
3 6
4#[export_name = "__pender"] 7#[unsafe(export_name = "__pender")]
5#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] 8#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))]
6fn __pender(context: *mut ()) { 9fn __pender(context: *mut ()) {
7 // `context` is always `usize::MAX` created by `Executor::run`. 10 // `context` is always `usize::MAX` created by `Executor::run`.
@@ -10,7 +13,7 @@ fn __pender(context: *mut ()) {
10 #[cfg(feature = "executor-thread")] 13 #[cfg(feature = "executor-thread")]
11 // Try to make Rust optimize the branching away if we only use thread mode. 14 // Try to make Rust optimize the branching away if we only use thread mode.
12 if !cfg!(feature = "executor-interrupt") || context == THREAD_PENDER { 15 if !cfg!(feature = "executor-interrupt") || context == THREAD_PENDER {
13 cortex_ar::asm::sev(); 16 aarch32_cpu::asm::sev();
14 return; 17 return;
15 } 18 }
16} 19}
@@ -23,10 +26,10 @@ mod thread {
23 26
24 use core::marker::PhantomData; 27 use core::marker::PhantomData;
25 28
26 use cortex_ar::asm::wfe; 29 use aarch32_cpu::asm::wfe;
27 pub use embassy_executor_macros::main_cortex_ar as main; 30 pub use embassy_executor_macros::main_cortex_ar as main;
28 31
29 use crate::{raw, Spawner}; 32 use crate::{Spawner, raw};
30 33
31 /// Thread mode executor, using WFE/SEV. 34 /// Thread mode executor, using WFE/SEV.
32 /// 35 ///
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index 1c9ddd8a0..1ce96d1d5 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -1,4 +1,4 @@
1#[export_name = "__pender"] 1#[unsafe(export_name = "__pender")]
2#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] 2#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))]
3fn __pender(context: *mut ()) { 3fn __pender(context: *mut ()) {
4 unsafe { 4 unsafe {
@@ -53,7 +53,7 @@ mod thread {
53 53
54 pub use embassy_executor_macros::main_cortex_m as main; 54 pub use embassy_executor_macros::main_cortex_m as main;
55 55
56 use crate::{raw, Spawner}; 56 use crate::{Spawner, raw};
57 57
58 /// Thread mode executor, using WFE/SEV. 58 /// Thread mode executor, using WFE/SEV.
59 /// 59 ///
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index 01e63a9fd..c70c1344a 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -10,12 +10,12 @@ mod thread {
10 10
11 pub use embassy_executor_macros::main_riscv as main; 11 pub use embassy_executor_macros::main_riscv as main;
12 12
13 use crate::{raw, Spawner}; 13 use crate::{Spawner, raw};
14 14
15 /// global atomic used to keep track of whether there is work to do since sev() is not available on RISCV 15 /// global atomic used to keep track of whether there is work to do since sev() is not available on RISCV
16 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); 16 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
17 17
18 #[export_name = "__pender"] 18 #[unsafe(export_name = "__pender")]
19 fn __pender(_context: *mut ()) { 19 fn __pender(_context: *mut ()) {
20 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); 20 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
21 } 21 }
diff --git a/embassy-executor/src/arch/spin.rs b/embassy-executor/src/arch/spin.rs
index 340023620..49f3356a6 100644
--- a/embassy-executor/src/arch/spin.rs
+++ b/embassy-executor/src/arch/spin.rs
@@ -9,9 +9,9 @@ mod thread {
9 9
10 pub use embassy_executor_macros::main_spin as main; 10 pub use embassy_executor_macros::main_spin as main;
11 11
12 use crate::{raw, Spawner}; 12 use crate::{Spawner, raw};
13 13
14 #[export_name = "__pender"] 14 #[unsafe(export_name = "__pender")]
15 fn __pender(_context: *mut ()) {} 15 fn __pender(_context: *mut ()) {}
16 16
17 /// Spin Executor 17 /// Spin Executor
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs
index b02b15988..c62ab723b 100644
--- a/embassy-executor/src/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
@@ -10,9 +10,9 @@ mod thread {
10 10
11 pub use embassy_executor_macros::main_std as main; 11 pub use embassy_executor_macros::main_std as main;
12 12
13 use crate::{raw, Spawner}; 13 use crate::{Spawner, raw};
14 14
15 #[export_name = "__pender"] 15 #[unsafe(export_name = "__pender")]
16 fn __pender(context: *mut ()) { 16 fn __pender(context: *mut ()) {
17 let signaler: &'static Signaler = unsafe { std::mem::transmute(context) }; 17 let signaler: &'static Signaler = unsafe { std::mem::transmute(context) };
18 signaler.signal() 18 signaler.signal()
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs
index f9d0f935c..d2ff2fe51 100644
--- a/embassy-executor/src/arch/wasm.rs
+++ b/embassy-executor/src/arch/wasm.rs
@@ -13,9 +13,9 @@ mod thread {
13 use wasm_bindgen::prelude::*; 13 use wasm_bindgen::prelude::*;
14 14
15 use crate::raw::util::UninitCell; 15 use crate::raw::util::UninitCell;
16 use crate::{raw, Spawner}; 16 use crate::{Spawner, raw};
17 17
18 #[export_name = "__pender"] 18 #[unsafe(export_name = "__pender")]
19 fn __pender(context: *mut ()) { 19 fn __pender(context: *mut ()) {
20 let signaler: &'static WasmContext = unsafe { std::mem::transmute(context) }; 20 let signaler: &'static WasmContext = unsafe { std::mem::transmute(context) };
21 let _ = signaler.promise.then(unsafe { signaler.closure.as_mut() }); 21 let _ = signaler.promise.then(unsafe { signaler.closure.as_mut() });
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index e47b8eb9f..cffc76699 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -1,5 +1,6 @@
1#![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] 1#![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)]
2#![allow(clippy::new_without_default)] 2#![allow(clippy::new_without_default)]
3#![allow(unsafe_op_in_unsafe_fn)]
3#![doc = include_str!("../README.md")] 4#![doc = include_str!("../README.md")]
4#![warn(missing_docs)] 5#![warn(missing_docs)]
5 6
diff --git a/embassy-executor/src/metadata.rs b/embassy-executor/src/metadata.rs
index bc0df0f83..76504ab0b 100644
--- a/embassy-executor/src/metadata.rs
+++ b/embassy-executor/src/metadata.rs
@@ -1,6 +1,6 @@
1#[cfg(feature = "metadata-name")] 1#[cfg(feature = "metadata-name")]
2use core::cell::Cell; 2use core::cell::Cell;
3use core::future::{poll_fn, Future}; 3use core::future::{Future, poll_fn};
4#[cfg(feature = "scheduler-priority")] 4#[cfg(feature = "scheduler-priority")]
5use core::sync::atomic::{AtomicU8, Ordering}; 5use core::sync::atomic::{AtomicU8, Ordering};
6use core::task::Poll; 6use core::task::Poll;
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 9f36c60bc..ab845ed3b 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -52,7 +52,7 @@ pub use self::waker::task_from_waker;
52use super::SpawnToken; 52use super::SpawnToken;
53use crate::{Metadata, SpawnError}; 53use crate::{Metadata, SpawnError};
54 54
55#[no_mangle] 55#[unsafe(no_mangle)]
56extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem { 56extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem {
57 unsafe { task_from_waker(waker).timer_queue_item() } 57 unsafe { task_from_waker(waker).timer_queue_item() }
58} 58}
@@ -407,7 +407,7 @@ unsafe impl Sync for Pender {}
407 407
408impl Pender { 408impl Pender {
409 pub(crate) fn pend(self) { 409 pub(crate) fn pend(self) {
410 extern "Rust" { 410 unsafe extern "Rust" {
411 fn __pender(context: *mut ()); 411 fn __pender(context: *mut ());
412 } 412 }
413 unsafe { __pender(self.0) }; 413 unsafe { __pender(self.0) };
@@ -507,7 +507,7 @@ impl SyncExecutor {
507/// The pender function must be exported with the name `__pender` and have the following signature: 507/// The pender function must be exported with the name `__pender` and have the following signature:
508/// 508///
509/// ```rust 509/// ```rust
510/// #[export_name = "__pender"] 510/// #[unsafe(export_name = "__pender")]
511/// fn pender(context: *mut ()) { 511/// fn pender(context: *mut ()) {
512/// // schedule `poll()` to be called 512/// // schedule `poll()` to be called
513/// } 513/// }
@@ -564,8 +564,6 @@ impl Executor {
564 /// 564 ///
565 /// # Safety 565 /// # Safety
566 /// 566 ///
567 /// You must call `initialize` before calling this method.
568 ///
569 /// You must NOT call `poll` reentrantly on the same executor. 567 /// You must NOT call `poll` reentrantly on the same executor.
570 /// 568 ///
571 /// In particular, note that `poll` may call the pender synchronously. Therefore, you 569 /// In particular, note that `poll` may call the pender synchronously. Therefore, you
diff --git a/embassy-executor/src/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs
index b8b052310..6f2abdbd0 100644
--- a/embassy-executor/src/raw/run_queue.rs
+++ b/embassy-executor/src/raw/run_queue.rs
@@ -1,9 +1,9 @@
1use core::ptr::{addr_of_mut, NonNull}; 1use core::ptr::{NonNull, addr_of_mut};
2 2
3use cordyceps::sorted_list::Links;
4use cordyceps::Linked; 3use cordyceps::Linked;
5#[cfg(any(feature = "scheduler-priority", feature = "scheduler-deadline"))] 4#[cfg(any(feature = "scheduler-priority", feature = "scheduler-deadline"))]
6use cordyceps::SortedList; 5use cordyceps::SortedList;
6use cordyceps::sorted_list::Links;
7 7
8#[cfg(target_has_atomic = "ptr")] 8#[cfg(target_has_atomic = "ptr")]
9type TransferStack<T> = cordyceps::TransferStack<T>; 9type TransferStack<T> = cordyceps::TransferStack<T>;
diff --git a/embassy-executor/src/raw/state_atomics_arm.rs b/embassy-executor/src/raw/state_atomics_arm.rs
index b743dcc2c..f68de955f 100644
--- a/embassy-executor/src/raw/state_atomics_arm.rs
+++ b/embassy-executor/src/raw/state_atomics_arm.rs
@@ -1,4 +1,4 @@
1use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering}; 1use core::sync::atomic::{AtomicBool, AtomicU32, Ordering, compiler_fence};
2 2
3#[derive(Clone, Copy)] 3#[derive(Clone, Copy)]
4pub(crate) struct Token(()); 4pub(crate) struct Token(());
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs
index b69a6ac66..8d7ef2892 100644
--- a/embassy-executor/src/raw/state_critical_section.rs
+++ b/embassy-executor/src/raw/state_critical_section.rs
@@ -1,7 +1,7 @@
1use core::cell::Cell; 1use core::cell::Cell;
2 2
3pub(crate) use critical_section::{with as locked, CriticalSection as Token};
4use critical_section::{CriticalSection, Mutex}; 3use critical_section::{CriticalSection, Mutex};
4pub(crate) use critical_section::{CriticalSection as Token, with as locked};
5 5
6#[cfg(target_arch = "avr")] 6#[cfg(target_arch = "avr")]
7type StateBits = u8; 7type StateBits = u8;
diff --git a/embassy-executor/src/raw/trace.rs b/embassy-executor/src/raw/trace.rs
index b3086948c..830162039 100644
--- a/embassy-executor/src/raw/trace.rs
+++ b/embassy-executor/src/raw/trace.rs
@@ -169,7 +169,7 @@ impl TaskTracker {
169} 169}
170 170
171#[cfg(feature = "trace")] 171#[cfg(feature = "trace")]
172extern "Rust" { 172unsafe extern "Rust" {
173 /// This callback is called when the executor begins polling. This will always 173 /// This callback is called when the executor begins polling. This will always
174 /// be paired with a later call to `_embassy_trace_executor_idle`. 174 /// be paired with a later call to `_embassy_trace_executor_idle`.
175 /// 175 ///
@@ -368,11 +368,7 @@ impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor {
368 } 368 }
369 fn time() -> u64 { 369 fn time() -> u64 {
370 const fn gcd(a: u64, b: u64) -> u64 { 370 const fn gcd(a: u64, b: u64) -> u64 {
371 if b == 0 { 371 if b == 0 { a } else { gcd(b, a % b) }
372 a
373 } else {
374 gcd(b, a % b)
375 }
376 } 372 }
377 373
378 const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000); 374 const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000);
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index d0d7b003d..2706f0fdf 100644
--- a/embassy-executor/src/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -1,6 +1,6 @@
1use core::task::{RawWaker, RawWakerVTable, Waker}; 1use core::task::{RawWaker, RawWakerVTable, Waker};
2 2
3use super::{wake_task, TaskHeader, TaskRef}; 3use super::{TaskHeader, TaskRef, wake_task};
4 4
5static VTABLE: RawWakerVTable = RawWakerVTable::new(clone, wake, wake, drop); 5static VTABLE: RawWakerVTable = RawWakerVTable::new(clone, wake, wake, drop);
6 6
@@ -35,7 +35,9 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef {
35 // make sure to compare vtable addresses. Doing `==` on the references 35 // make sure to compare vtable addresses. Doing `==` on the references
36 // will compare the contents, which is slower. 36 // will compare the contents, which is slower.
37 if waker.vtable() as *const _ != &VTABLE as *const _ { 37 if waker.vtable() as *const _ != &VTABLE as *const _ {
38 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") 38 panic!(
39 "Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor."
40 )
39 } 41 }
40 // safety: our wakers are always created with `TaskRef::as_ptr` 42 // safety: our wakers are always created with `TaskRef::as_ptr`
41 unsafe { TaskRef::from_ptr(waker.data() as *const TaskHeader) } 43 unsafe { TaskRef::from_ptr(waker.data() as *const TaskHeader) }
diff --git a/embassy-executor/src/raw/waker_turbo.rs b/embassy-executor/src/raw/waker_turbo.rs
index 435a0ff7e..919bcc61a 100644
--- a/embassy-executor/src/raw/waker_turbo.rs
+++ b/embassy-executor/src/raw/waker_turbo.rs
@@ -1,7 +1,7 @@
1use core::ptr::NonNull; 1use core::ptr::NonNull;
2use core::task::Waker; 2use core::task::Waker;
3 3
4use super::{wake_task, TaskHeader, TaskRef}; 4use super::{TaskHeader, TaskRef, wake_task};
5 5
6pub(crate) unsafe fn from_task(p: TaskRef) -> Waker { 6pub(crate) unsafe fn from_task(p: TaskRef) -> Waker {
7 Waker::from_turbo_ptr(NonNull::new_unchecked(p.as_ptr() as _)) 7 Waker::from_turbo_ptr(NonNull::new_unchecked(p.as_ptr() as _))
@@ -26,7 +26,7 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef {
26} 26}
27 27
28#[inline(never)] 28#[inline(never)]
29#[no_mangle] 29#[unsafe(no_mangle)]
30fn _turbo_wake(ptr: NonNull<()>) { 30fn _turbo_wake(ptr: NonNull<()>) {
31 // safety: our wakers are always created with `TaskRef::as_ptr` 31 // safety: our wakers are always created with `TaskRef::as_ptr`
32 let task = unsafe { TaskRef::from_ptr(ptr.as_ptr() as *const TaskHeader) }; 32 let task = unsafe { TaskRef::from_ptr(ptr.as_ptr() as *const TaskHeader) };
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs
index 83d896b76..b73a1e7c6 100644
--- a/embassy-executor/src/spawner.rs
+++ b/embassy-executor/src/spawner.rs
@@ -1,4 +1,4 @@
1use core::future::{poll_fn, Future}; 1use core::future::{Future, poll_fn};
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3use core::mem; 3use core::mem;
4use core::sync::atomic::Ordering; 4use core::sync::atomic::Ordering;
@@ -75,7 +75,10 @@ impl core::fmt::Debug for SpawnError {
75impl core::fmt::Display for SpawnError { 75impl core::fmt::Display for SpawnError {
76 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 76 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 match self { 77 match self {
78 SpawnError::Busy => write!(f, "Busy - Too many instances of this task are already running. Check the `pool_size` attribute of the task."), 78 SpawnError::Busy => write!(
79 f,
80 "Busy - Too many instances of this task are already running. Check the `pool_size` attribute of the task."
81 ),
79 } 82 }
80 } 83 }
81} 84}
@@ -84,7 +87,10 @@ impl core::fmt::Display for SpawnError {
84impl defmt::Format for SpawnError { 87impl defmt::Format for SpawnError {
85 fn format(&self, f: defmt::Formatter) { 88 fn format(&self, f: defmt::Formatter) {
86 match self { 89 match self {
87 SpawnError::Busy => defmt::write!(f, "Busy - Too many instances of this task are already running. Check the `pool_size` attribute of the task."), 90 SpawnError::Busy => defmt::write!(
91 f,
92 "Busy - Too many instances of this task are already running. Check the `pool_size` attribute of the task."
93 ),
88 } 94 }
89 } 95 }
90} 96}
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs
index 6baf3dc21..a99976168 100644
--- a/embassy-executor/tests/test.rs
+++ b/embassy-executor/tests/test.rs
@@ -2,14 +2,14 @@
2#![cfg_attr(feature = "nightly", feature(never_type))] 2#![cfg_attr(feature = "nightly", feature(never_type))]
3 3
4use std::boxed::Box; 4use std::boxed::Box;
5use std::future::{poll_fn, Future}; 5use std::future::{Future, poll_fn};
6use std::sync::{Arc, Mutex}; 6use std::sync::{Arc, Mutex};
7use std::task::Poll; 7use std::task::Poll;
8 8
9use embassy_executor::raw::Executor; 9use embassy_executor::raw::Executor;
10use embassy_executor::{task, Spawner}; 10use embassy_executor::{Spawner, task};
11 11
12#[export_name = "__pender"] 12#[unsafe(export_name = "__pender")]
13fn __pender(context: *mut ()) { 13fn __pender(context: *mut ()) {
14 unsafe { 14 unsafe {
15 let trace = &*(context as *const Trace); 15 let trace = &*(context as *const Trace);
diff --git a/embassy-executor/tests/ui/nonstatic_struct_elided.stderr b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr
index 0ee1bfe0c..e6829bf5d 100644
--- a/embassy-executor/tests/ui/nonstatic_struct_elided.stderr
+++ b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr
@@ -9,16 +9,16 @@ help: indicate the anonymous lifetime
96 | async fn task(_x: Foo<'_>) {} 96 | async fn task(_x: Foo<'_>) {}
10 | ++++ 10 | ++++
11 11
12error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds 12error: lifetime may not live long enough
13 --> tests/ui/nonstatic_struct_elided.rs:5:1 13 --> tests/ui/nonstatic_struct_elided.rs:5:1
14 | 14 |
155 | #[embassy_executor::task] 155 | #[embassy_executor::task]
16 | ^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type defined here 16 | ^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
176 | async fn task(_x: Foo) {} 176 | async fn task(_x: Foo) {}
18 | --- hidden type `impl Sized` captures the anonymous lifetime defined here 18 | -- has type `Foo<'1>`
19 | 19 |
20 = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) 20 = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info)
21help: add a `use<...>` bound to explicitly capture `'_` 21help: to declare that `impl Sized` captures data from argument `_x`, you can add an explicit `'_` lifetime bound
22 | 22 |
235 | #[embassy_executor::task] + use<'_> 235 | #[embassy_executor::task] + '_
24 | +++++++++ 24 | ++++
diff --git a/embassy-executor/tests/ui/spawn_nonsend.rs b/embassy-executor/tests/ui/spawn_nonsend.rs
index 601041941..a06c0b37a 100644
--- a/embassy-executor/tests/ui/spawn_nonsend.rs
+++ b/embassy-executor/tests/ui/spawn_nonsend.rs
@@ -1,7 +1,5 @@
1#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] 1#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))]
2 2
3use core::future::Future;
4
5use embassy_executor::SendSpawner; 3use embassy_executor::SendSpawner;
6 4
7#[embassy_executor::task] 5#[embassy_executor::task]
diff --git a/embassy-executor/tests/ui/spawn_nonsend.stderr b/embassy-executor/tests/ui/spawn_nonsend.stderr
index 25bd7d78d..31efadd49 100644
--- a/embassy-executor/tests/ui/spawn_nonsend.stderr
+++ b/embassy-executor/tests/ui/spawn_nonsend.stderr
@@ -1,27 +1,19 @@
1warning: unused import: `core::future::Future`
2 --> tests/ui/spawn_nonsend.rs:3:5
3 |
43 | use core::future::Future;
5 | ^^^^^^^^^^^^^^^^^^^^
6 |
7 = note: `#[warn(unused_imports)]` on by default
8
9error[E0277]: `*mut ()` cannot be sent between threads safely 1error[E0277]: `*mut ()` cannot be sent between threads safely
10 --> tests/ui/spawn_nonsend.rs:13:13 2 --> tests/ui/spawn_nonsend.rs:11:13
11 | 3 |
127 | #[embassy_executor::task] 4 5 | #[embassy_executor::task]
13 | ------------------------- within this `impl Sized` 5 | ------------------------- within this `impl Sized`
14... 6...
1513 | s.spawn(task(core::ptr::null_mut()).unwrap()); 711 | s.spawn(task(core::ptr::null_mut()).unwrap());
16 | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut ()` cannot be sent between threads safely 8 | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut ()` cannot be sent between threads safely
17 | | 9 | |
18 | required by a bound introduced by this call 10 | required by a bound introduced by this call
19 | 11 |
20 = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()` 12 = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()`
21note: required because it's used within this closure 13note: required because it's used within this closure
22 --> tests/ui/spawn_nonsend.rs:7:1 14 --> tests/ui/spawn_nonsend.rs:5:1
23 | 15 |
247 | #[embassy_executor::task] 16 5 | #[embassy_executor::task]
25 | ^^^^^^^^^^^^^^^^^^^^^^^^^ 17 | ^^^^^^^^^^^^^^^^^^^^^^^^^
26note: required because it appears within the type `impl Sized` 18note: required because it appears within the type `impl Sized`
27 --> src/raw/mod.rs 19 --> src/raw/mod.rs
@@ -29,9 +21,9 @@ note: required because it appears within the type `impl Sized`
29 | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> Result<SpawnToken<impl Sized>, SpawnError> 21 | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> Result<SpawnToken<impl Sized>, SpawnError>
30 | ^^^^^^^^^^ 22 | ^^^^^^^^^^
31note: required because it appears within the type `impl Sized` 23note: required because it appears within the type `impl Sized`
32 --> tests/ui/spawn_nonsend.rs:7:1 24 --> tests/ui/spawn_nonsend.rs:5:1
33 | 25 |
347 | #[embassy_executor::task] 26 5 | #[embassy_executor::task]
35 | ^^^^^^^^^^^^^^^^^^^^^^^^^ 27 | ^^^^^^^^^^^^^^^^^^^^^^^^^
36note: required by a bound in `SendSpawner::spawn` 28note: required by a bound in `SendSpawner::spawn`
37 --> src/spawner.rs 29 --> src/spawner.rs
diff --git a/embassy-executor/tests/ui/task_safety_attribute.rs b/embassy-executor/tests/ui/task_safety_attribute.rs
index ab5a2f99f..46a5c665f 100644
--- a/embassy-executor/tests/ui/task_safety_attribute.rs
+++ b/embassy-executor/tests/ui/task_safety_attribute.rs
@@ -9,7 +9,7 @@ async fn safe() {}
9#[embassy_executor::task] 9#[embassy_executor::task]
10async unsafe fn not_safe() {} 10async unsafe fn not_safe() {}
11 11
12#[export_name = "__pender"] 12#[unsafe(export_name = "__pender")]
13fn pender(_: *mut ()) { 13fn pender(_: *mut ()) {
14 // The test doesn't link if we don't include this. 14 // The test doesn't link if we don't include this.
15 // We never call this anyway. 15 // We never call this anyway.
diff --git a/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr
index d987a4b95..033395584 100644
--- a/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr
+++ b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr
@@ -4,7 +4,7 @@ error[E0133]: call to unsafe function `std::ptr::const_ptr::<impl *const T>::rea
47 | (&x as *const i32).read(); 47 | (&x as *const i32).read();
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
6 | 6 |
7 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html> 7 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>
8 = note: consult the function's documentation for information on how to avoid undefined behavior 8 = note: consult the function's documentation for information on how to avoid undefined behavior
9note: an unsafe function restricts its caller, but its body is safe by default 9note: an unsafe function restricts its caller, but its body is safe by default
10 --> tests/ui/unsafe_op_in_unsafe_task.rs:5:1 10 --> tests/ui/unsafe_op_in_unsafe_task.rs:5:1