diff options
| author | Peter Krull <[email protected]> | 2024-09-23 19:02:59 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-23 19:02:59 +0200 |
| commit | a2c473306f4a7c8e99add2546450ab3a7a97436e (patch) | |
| tree | 5522a708e492db7d4632dc0a56fe5057244f03f0 /embassy-executor | |
| parent | e02a987bafd4f0fcf9d80e7c4f6e1504b8b02cec (diff) | |
| parent | 2935290a6222536d6341103f91bfd732165d3862 (diff) | |
Merge branch 'embassy-rs:main' into multi-signal
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/CHANGELOG.md | 6 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 11 | ||||
| -rw-r--r-- | embassy-executor/build.rs | 31 | ||||
| -rw-r--r-- | embassy-executor/build_common.rs | 94 | ||||
| -rw-r--r-- | embassy-executor/src/arch/riscv32.rs | 2 | ||||
| -rw-r--r-- | embassy-executor/src/fmt.rs | 34 | ||||
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-executor/src/raw/waker.rs | 38 | ||||
| -rw-r--r-- | embassy-executor/tests/test.rs | 2 |
9 files changed, 160 insertions, 60 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 77c64fd8e..5582b56ec 100644 --- a/embassy-executor/CHANGELOG.md +++ b/embassy-executor/CHANGELOG.md | |||
| @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 7 | 7 | ||
| 8 | ## Unreleased | 8 | ## Unreleased |
| 9 | 9 | ||
| 10 | ## 0.6.0 - 2024-08-05 | ||
| 11 | |||
| 12 | - Add collapse_debuginfo to fmt.rs macros. | ||
| 13 | - initial support for avr | ||
| 14 | - use nightly waker_getters APIs | ||
| 15 | |||
| 10 | ## 0.5.0 - 2024-01-11 | 16 | ## 0.5.0 - 2024-01-11 |
| 11 | 17 | ||
| 12 | - Updated to `embassy-time-driver 0.1`, `embassy-time-queue-driver 0.1`, compatible with `embassy-time v0.3` and higher. | 18 | - Updated to `embassy-time-driver 0.1`, `embassy-time-queue-driver 0.1`, compatible with `embassy-time v0.3` and higher. |
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 409df0d75..01fa28b88 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "embassy-executor" | 2 | name = "embassy-executor" |
| 3 | version = "0.5.0" | 3 | version = "0.6.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | description = "async/await executor designed for embedded usage" | 6 | description = "async/await executor designed for embedded usage" |
| @@ -33,15 +33,14 @@ defmt = { version = "0.3", optional = true } | |||
| 33 | log = { version = "0.4.14", optional = true } | 33 | log = { version = "0.4.14", optional = true } |
| 34 | rtos-trace = { version = "0.1.2", optional = true } | 34 | rtos-trace = { version = "0.1.2", optional = true } |
| 35 | 35 | ||
| 36 | embassy-executor-macros = { version = "0.4.0", path = "../embassy-executor-macros" } | 36 | embassy-executor-macros = { version = "0.5.0", path = "../embassy-executor-macros" } |
| 37 | embassy-time-driver = { version = "0.1.0", path = "../embassy-time-driver", optional = true } | 37 | embassy-time-driver = { version = "0.1.0", path = "../embassy-time-driver", optional = true } |
| 38 | embassy-time-queue-driver = { version = "0.1.0", path = "../embassy-time-queue-driver", optional = true } | 38 | embassy-time-queue-driver = { version = "0.1.0", path = "../embassy-time-queue-driver", optional = true } |
| 39 | critical-section = "1.1" | 39 | critical-section = "1.1" |
| 40 | 40 | ||
| 41 | document-features = "0.2.7" | 41 | document-features = "0.2.7" |
| 42 | 42 | ||
| 43 | # needed for riscv and avr | 43 | # needed for AVR |
| 44 | # remove when https://github.com/rust-lang/rust/pull/114499 lands on stable (on 1.76) | ||
| 45 | portable-atomic = { version = "1.5", optional = true } | 44 | portable-atomic = { version = "1.5", optional = true } |
| 46 | 45 | ||
| 47 | # arch-cortex-m dependencies | 46 | # arch-cortex-m dependencies |
| @@ -78,9 +77,9 @@ arch-std = ["_arch", "critical-section/std"] | |||
| 78 | ## Cortex-M | 77 | ## Cortex-M |
| 79 | arch-cortex-m = ["_arch", "dep:cortex-m"] | 78 | arch-cortex-m = ["_arch", "dep:cortex-m"] |
| 80 | ## RISC-V 32 | 79 | ## RISC-V 32 |
| 81 | arch-riscv32 = ["_arch", "dep:portable-atomic"] | 80 | arch-riscv32 = ["_arch"] |
| 82 | ## WASM | 81 | ## WASM |
| 83 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] | 82 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys", "critical-section/std"] |
| 84 | ## AVR | 83 | ## AVR |
| 85 | arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"] | 84 | arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"] |
| 86 | 85 | ||
diff --git a/embassy-executor/build.rs b/embassy-executor/build.rs index 07f31e3fb..8a41d7503 100644 --- a/embassy-executor/build.rs +++ b/embassy-executor/build.rs | |||
| @@ -3,6 +3,9 @@ use std::fmt::Write; | |||
| 3 | use std::path::PathBuf; | 3 | use std::path::PathBuf; |
| 4 | use std::{env, fs}; | 4 | use std::{env, fs}; |
| 5 | 5 | ||
| 6 | #[path = "./build_common.rs"] | ||
| 7 | mod common; | ||
| 8 | |||
| 6 | static CONFIGS: &[(&str, usize)] = &[ | 9 | static CONFIGS: &[(&str, usize)] = &[ |
| 7 | // BEGIN AUTOGENERATED CONFIG FEATURES | 10 | // BEGIN AUTOGENERATED CONFIG FEATURES |
| 8 | // Generated by gen_config.py. DO NOT EDIT. | 11 | // Generated by gen_config.py. DO NOT EDIT. |
| @@ -91,30 +94,6 @@ fn main() { | |||
| 91 | let out_file = out_dir.join("config.rs").to_string_lossy().to_string(); | 94 | let out_file = out_dir.join("config.rs").to_string_lossy().to_string(); |
| 92 | fs::write(out_file, data).unwrap(); | 95 | fs::write(out_file, data).unwrap(); |
| 93 | 96 | ||
| 94 | // cortex-m targets | 97 | let mut rustc_cfgs = common::CfgSet::new(); |
| 95 | let target = env::var("TARGET").unwrap(); | 98 | common::set_target_cfgs(&mut rustc_cfgs); |
| 96 | |||
| 97 | if target.starts_with("thumbv6m-") { | ||
| 98 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 99 | println!("cargo:rustc-cfg=armv6m"); | ||
| 100 | } else if target.starts_with("thumbv7m-") { | ||
| 101 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 102 | println!("cargo:rustc-cfg=armv7m"); | ||
| 103 | } else if target.starts_with("thumbv7em-") { | ||
| 104 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 105 | println!("cargo:rustc-cfg=armv7m"); | ||
| 106 | println!("cargo:rustc-cfg=armv7em"); // (not currently used) | ||
| 107 | } else if target.starts_with("thumbv8m.base") { | ||
| 108 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 109 | println!("cargo:rustc-cfg=armv8m"); | ||
| 110 | println!("cargo:rustc-cfg=armv8m_base"); | ||
| 111 | } else if target.starts_with("thumbv8m.main") { | ||
| 112 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 113 | println!("cargo:rustc-cfg=armv8m"); | ||
| 114 | println!("cargo:rustc-cfg=armv8m_main"); | ||
| 115 | } | ||
| 116 | |||
| 117 | if target.ends_with("-eabihf") { | ||
| 118 | println!("cargo:rustc-cfg=has_fpu"); | ||
| 119 | } | ||
| 120 | } | 99 | } |
diff --git a/embassy-executor/build_common.rs b/embassy-executor/build_common.rs new file mode 100644 index 000000000..4f24e6d37 --- /dev/null +++ b/embassy-executor/build_common.rs | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | // NOTE: this file is copy-pasted between several Embassy crates, because there is no | ||
| 2 | // straightforward way to share this code: | ||
| 3 | // - it cannot be placed into the root of the repo and linked from each build.rs using `#[path = | ||
| 4 | // "../build_common.rs"]`, because `cargo publish` requires that all files published with a crate | ||
| 5 | // reside in the crate's directory, | ||
| 6 | // - it cannot be symlinked from `embassy-xxx/build_common.rs` to `../build_common.rs`, because | ||
| 7 | // symlinks don't work on Windows. | ||
| 8 | |||
| 9 | use std::collections::HashSet; | ||
| 10 | use std::env; | ||
| 11 | |||
| 12 | /// Helper for emitting cargo instruction for enabling configs (`cargo:rustc-cfg=X`) and declaring | ||
| 13 | /// them (`cargo:rust-check-cfg=cfg(X)`). | ||
| 14 | #[derive(Debug)] | ||
| 15 | pub struct CfgSet { | ||
| 16 | enabled: HashSet<String>, | ||
| 17 | declared: HashSet<String>, | ||
| 18 | } | ||
| 19 | |||
| 20 | impl CfgSet { | ||
| 21 | pub fn new() -> Self { | ||
| 22 | Self { | ||
| 23 | enabled: HashSet::new(), | ||
| 24 | declared: HashSet::new(), | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | /// Enable a config, which can then be used in `#[cfg(...)]` for conditional compilation. | ||
| 29 | /// | ||
| 30 | /// All configs that can potentially be enabled should be unconditionally declared using | ||
| 31 | /// [`Self::declare()`]. | ||
| 32 | pub fn enable(&mut self, cfg: impl AsRef<str>) { | ||
| 33 | if self.enabled.insert(cfg.as_ref().to_owned()) { | ||
| 34 | println!("cargo:rustc-cfg={}", cfg.as_ref()); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | pub fn enable_all(&mut self, cfgs: &[impl AsRef<str>]) { | ||
| 39 | for cfg in cfgs.iter() { | ||
| 40 | self.enable(cfg.as_ref()); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | /// Declare a valid config for conditional compilation, without enabling it. | ||
| 45 | /// | ||
| 46 | /// This enables rustc to check that the configs in `#[cfg(...)]` attributes are valid. | ||
| 47 | pub fn declare(&mut self, cfg: impl AsRef<str>) { | ||
| 48 | if self.declared.insert(cfg.as_ref().to_owned()) { | ||
| 49 | println!("cargo:rustc-check-cfg=cfg({})", cfg.as_ref()); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | pub fn declare_all(&mut self, cfgs: &[impl AsRef<str>]) { | ||
| 54 | for cfg in cfgs.iter() { | ||
| 55 | self.declare(cfg.as_ref()); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | pub fn set(&mut self, cfg: impl Into<String>, enable: bool) { | ||
| 60 | let cfg = cfg.into(); | ||
| 61 | if enable { | ||
| 62 | self.enable(cfg.clone()); | ||
| 63 | } | ||
| 64 | self.declare(cfg); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | /// Sets configs that describe the target platform. | ||
| 69 | pub fn set_target_cfgs(cfgs: &mut CfgSet) { | ||
| 70 | let target = env::var("TARGET").unwrap(); | ||
| 71 | |||
| 72 | if target.starts_with("thumbv6m-") { | ||
| 73 | cfgs.enable_all(&["cortex_m", "armv6m"]); | ||
| 74 | } else if target.starts_with("thumbv7m-") { | ||
| 75 | cfgs.enable_all(&["cortex_m", "armv7m"]); | ||
| 76 | } else if target.starts_with("thumbv7em-") { | ||
| 77 | cfgs.enable_all(&["cortex_m", "armv7m", "armv7em"]); | ||
| 78 | } else if target.starts_with("thumbv8m.base") { | ||
| 79 | cfgs.enable_all(&["cortex_m", "armv8m", "armv8m_base"]); | ||
| 80 | } else if target.starts_with("thumbv8m.main") { | ||
| 81 | cfgs.enable_all(&["cortex_m", "armv8m", "armv8m_main"]); | ||
| 82 | } | ||
| 83 | cfgs.declare_all(&[ | ||
| 84 | "cortex_m", | ||
| 85 | "armv6m", | ||
| 86 | "armv7m", | ||
| 87 | "armv7em", | ||
| 88 | "armv8m", | ||
| 89 | "armv8m_base", | ||
| 90 | "armv8m_main", | ||
| 91 | ]); | ||
| 92 | |||
| 93 | cfgs.set("has_fpu", target.ends_with("-eabihf")); | ||
| 94 | } | ||
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs index c56f502d3..01e63a9fd 100644 --- a/embassy-executor/src/arch/riscv32.rs +++ b/embassy-executor/src/arch/riscv32.rs | |||
| @@ -6,9 +6,9 @@ pub use thread::*; | |||
| 6 | #[cfg(feature = "executor-thread")] | 6 | #[cfg(feature = "executor-thread")] |
| 7 | mod thread { | 7 | mod thread { |
| 8 | use core::marker::PhantomData; | 8 | use core::marker::PhantomData; |
| 9 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 9 | 10 | ||
| 10 | pub use embassy_executor_macros::main_riscv as main; | 11 | pub use embassy_executor_macros::main_riscv as main; |
| 11 | use portable_atomic::{AtomicBool, Ordering}; | ||
| 12 | 12 | ||
| 13 | use crate::{raw, Spawner}; | 13 | use crate::{raw, Spawner}; |
| 14 | 14 | ||
diff --git a/embassy-executor/src/fmt.rs b/embassy-executor/src/fmt.rs index 78e583c1c..8ca61bc39 100644 --- a/embassy-executor/src/fmt.rs +++ b/embassy-executor/src/fmt.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | 2 | #![allow(unused)] |
| 3 | 3 | ||
| 4 | use core::fmt::{Debug, Display, LowerHex}; | 4 | use core::fmt::{Debug, Display, LowerHex}; |
| 5 | 5 | ||
| 6 | #[cfg(all(feature = "defmt", feature = "log"))] | 6 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 7 | compile_error!("You may not enable both `defmt` and `log` features."); | 7 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 8 | 8 | ||
| 9 | #[collapse_debuginfo(yes)] | ||
| 9 | macro_rules! assert { | 10 | macro_rules! assert { |
| 10 | ($($x:tt)*) => { | 11 | ($($x:tt)*) => { |
| 11 | { | 12 | { |
| @@ -17,6 +18,7 @@ macro_rules! assert { | |||
| 17 | }; | 18 | }; |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 21 | #[collapse_debuginfo(yes)] | ||
| 20 | macro_rules! assert_eq { | 22 | macro_rules! assert_eq { |
| 21 | ($($x:tt)*) => { | 23 | ($($x:tt)*) => { |
| 22 | { | 24 | { |
| @@ -28,6 +30,7 @@ macro_rules! assert_eq { | |||
| 28 | }; | 30 | }; |
| 29 | } | 31 | } |
| 30 | 32 | ||
| 33 | #[collapse_debuginfo(yes)] | ||
| 31 | macro_rules! assert_ne { | 34 | macro_rules! assert_ne { |
| 32 | ($($x:tt)*) => { | 35 | ($($x:tt)*) => { |
| 33 | { | 36 | { |
| @@ -39,6 +42,7 @@ macro_rules! assert_ne { | |||
| 39 | }; | 42 | }; |
| 40 | } | 43 | } |
| 41 | 44 | ||
| 45 | #[collapse_debuginfo(yes)] | ||
| 42 | macro_rules! debug_assert { | 46 | macro_rules! debug_assert { |
| 43 | ($($x:tt)*) => { | 47 | ($($x:tt)*) => { |
| 44 | { | 48 | { |
| @@ -50,6 +54,7 @@ macro_rules! debug_assert { | |||
| 50 | }; | 54 | }; |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 57 | #[collapse_debuginfo(yes)] | ||
| 53 | macro_rules! debug_assert_eq { | 58 | macro_rules! debug_assert_eq { |
| 54 | ($($x:tt)*) => { | 59 | ($($x:tt)*) => { |
| 55 | { | 60 | { |
| @@ -61,6 +66,7 @@ macro_rules! debug_assert_eq { | |||
| 61 | }; | 66 | }; |
| 62 | } | 67 | } |
| 63 | 68 | ||
| 69 | #[collapse_debuginfo(yes)] | ||
| 64 | macro_rules! debug_assert_ne { | 70 | macro_rules! debug_assert_ne { |
| 65 | ($($x:tt)*) => { | 71 | ($($x:tt)*) => { |
| 66 | { | 72 | { |
| @@ -72,6 +78,7 @@ macro_rules! debug_assert_ne { | |||
| 72 | }; | 78 | }; |
| 73 | } | 79 | } |
| 74 | 80 | ||
| 81 | #[collapse_debuginfo(yes)] | ||
| 75 | macro_rules! todo { | 82 | macro_rules! todo { |
| 76 | ($($x:tt)*) => { | 83 | ($($x:tt)*) => { |
| 77 | { | 84 | { |
| @@ -83,20 +90,19 @@ macro_rules! todo { | |||
| 83 | }; | 90 | }; |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | #[cfg(not(feature = "defmt"))] | 93 | #[collapse_debuginfo(yes)] |
| 87 | macro_rules! unreachable { | 94 | macro_rules! unreachable { |
| 88 | ($($x:tt)*) => { | 95 | ($($x:tt)*) => { |
| 89 | ::core::unreachable!($($x)*) | 96 | { |
| 90 | }; | 97 | #[cfg(not(feature = "defmt"))] |
| 91 | } | 98 | ::core::unreachable!($($x)*); |
| 92 | 99 | #[cfg(feature = "defmt")] | |
| 93 | #[cfg(feature = "defmt")] | 100 | ::defmt::unreachable!($($x)*); |
| 94 | macro_rules! unreachable { | 101 | } |
| 95 | ($($x:tt)*) => { | ||
| 96 | ::defmt::unreachable!($($x)*) | ||
| 97 | }; | 102 | }; |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 105 | #[collapse_debuginfo(yes)] | ||
| 100 | macro_rules! panic { | 106 | macro_rules! panic { |
| 101 | ($($x:tt)*) => { | 107 | ($($x:tt)*) => { |
| 102 | { | 108 | { |
| @@ -108,6 +114,7 @@ macro_rules! panic { | |||
| 108 | }; | 114 | }; |
| 109 | } | 115 | } |
| 110 | 116 | ||
| 117 | #[collapse_debuginfo(yes)] | ||
| 111 | macro_rules! trace { | 118 | macro_rules! trace { |
| 112 | ($s:literal $(, $x:expr)* $(,)?) => { | 119 | ($s:literal $(, $x:expr)* $(,)?) => { |
| 113 | { | 120 | { |
| @@ -121,6 +128,7 @@ macro_rules! trace { | |||
| 121 | }; | 128 | }; |
| 122 | } | 129 | } |
| 123 | 130 | ||
| 131 | #[collapse_debuginfo(yes)] | ||
| 124 | macro_rules! debug { | 132 | macro_rules! debug { |
| 125 | ($s:literal $(, $x:expr)* $(,)?) => { | 133 | ($s:literal $(, $x:expr)* $(,)?) => { |
| 126 | { | 134 | { |
| @@ -134,6 +142,7 @@ macro_rules! debug { | |||
| 134 | }; | 142 | }; |
| 135 | } | 143 | } |
| 136 | 144 | ||
| 145 | #[collapse_debuginfo(yes)] | ||
| 137 | macro_rules! info { | 146 | macro_rules! info { |
| 138 | ($s:literal $(, $x:expr)* $(,)?) => { | 147 | ($s:literal $(, $x:expr)* $(,)?) => { |
| 139 | { | 148 | { |
| @@ -147,6 +156,7 @@ macro_rules! info { | |||
| 147 | }; | 156 | }; |
| 148 | } | 157 | } |
| 149 | 158 | ||
| 159 | #[collapse_debuginfo(yes)] | ||
| 150 | macro_rules! warn { | 160 | macro_rules! warn { |
| 151 | ($s:literal $(, $x:expr)* $(,)?) => { | 161 | ($s:literal $(, $x:expr)* $(,)?) => { |
| 152 | { | 162 | { |
| @@ -160,6 +170,7 @@ macro_rules! warn { | |||
| 160 | }; | 170 | }; |
| 161 | } | 171 | } |
| 162 | 172 | ||
| 173 | #[collapse_debuginfo(yes)] | ||
| 163 | macro_rules! error { | 174 | macro_rules! error { |
| 164 | ($s:literal $(, $x:expr)* $(,)?) => { | 175 | ($s:literal $(, $x:expr)* $(,)?) => { |
| 165 | { | 176 | { |
| @@ -174,6 +185,7 @@ macro_rules! error { | |||
| 174 | } | 185 | } |
| 175 | 186 | ||
| 176 | #[cfg(feature = "defmt")] | 187 | #[cfg(feature = "defmt")] |
| 188 | #[collapse_debuginfo(yes)] | ||
| 177 | macro_rules! unwrap { | 189 | macro_rules! unwrap { |
| 178 | ($($x:tt)*) => { | 190 | ($($x:tt)*) => { |
| 179 | ::defmt::unwrap!($($x)*) | 191 | ::defmt::unwrap!($($x)*) |
| @@ -181,6 +193,7 @@ macro_rules! unwrap { | |||
| 181 | } | 193 | } |
| 182 | 194 | ||
| 183 | #[cfg(not(feature = "defmt"))] | 195 | #[cfg(not(feature = "defmt"))] |
| 196 | #[collapse_debuginfo(yes)] | ||
| 184 | macro_rules! unwrap { | 197 | macro_rules! unwrap { |
| 185 | ($arg:expr) => { | 198 | ($arg:expr) => { |
| 186 | match $crate::fmt::Try::into_result($arg) { | 199 | match $crate::fmt::Try::into_result($arg) { |
| @@ -229,7 +242,6 @@ impl<T, E> Try for Result<T, E> { | |||
| 229 | } | 242 | } |
| 230 | } | 243 | } |
| 231 | 244 | ||
| 232 | #[allow(unused)] | ||
| 233 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | 245 | pub(crate) struct Bytes<'a>(pub &'a [u8]); |
| 234 | 246 | ||
| 235 | impl<'a> Debug for Bytes<'a> { | 247 | impl<'a> Debug for Bytes<'a> { |
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 3d5e3ab9f..d9ea5c005 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -30,7 +30,7 @@ use core::ptr::NonNull; | |||
| 30 | use core::task::{Context, Poll}; | 30 | use core::task::{Context, Poll}; |
| 31 | 31 | ||
| 32 | #[cfg(feature = "integrated-timers")] | 32 | #[cfg(feature = "integrated-timers")] |
| 33 | use embassy_time_driver::{self, AlarmHandle}; | 33 | use embassy_time_driver::AlarmHandle; |
| 34 | #[cfg(feature = "rtos-trace")] | 34 | #[cfg(feature = "rtos-trace")] |
| 35 | use rtos_trace::trace; | 35 | use rtos_trace::trace; |
| 36 | 36 | ||
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs index 522853e34..8bb2cfd05 100644 --- a/embassy-executor/src/raw/waker.rs +++ b/embassy-executor/src/raw/waker.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use core::mem; | ||
| 2 | use core::task::{RawWaker, RawWakerVTable, Waker}; | 1 | use core::task::{RawWaker, RawWakerVTable, Waker}; |
| 3 | 2 | ||
| 4 | use super::{wake_task, TaskHeader, TaskRef}; | 3 | use super::{wake_task, TaskHeader, TaskRef}; |
| @@ -33,20 +32,31 @@ pub(crate) unsafe fn from_task(p: TaskRef) -> Waker { | |||
| 33 | /// | 32 | /// |
| 34 | /// Panics if the waker is not created by the Embassy executor. | 33 | /// Panics if the waker is not created by the Embassy executor. |
| 35 | pub fn task_from_waker(waker: &Waker) -> TaskRef { | 34 | pub fn task_from_waker(waker: &Waker) -> TaskRef { |
| 36 | // safety: OK because WakerHack has the same layout as Waker. | 35 | let (vtable, data) = { |
| 37 | // This is not really guaranteed because the structs are `repr(Rust)`, it is | 36 | #[cfg(not(feature = "nightly"))] |
| 38 | // indeed the case in the current implementation. | 37 | { |
| 39 | // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 | 38 | struct WakerHack { |
| 40 | let hack: &WakerHack = unsafe { mem::transmute(waker) }; | 39 | data: *const (), |
| 41 | if hack.vtable != &VTABLE { | 40 | vtable: &'static RawWakerVTable, |
| 41 | } | ||
| 42 | |||
| 43 | // safety: OK because WakerHack has the same layout as Waker. | ||
| 44 | // This is not really guaranteed because the structs are `repr(Rust)`, it is | ||
| 45 | // indeed the case in the current implementation. | ||
| 46 | // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 | ||
| 47 | let hack: &WakerHack = unsafe { core::mem::transmute(waker) }; | ||
| 48 | (hack.vtable, hack.data) | ||
| 49 | } | ||
| 50 | |||
| 51 | #[cfg(feature = "nightly")] | ||
| 52 | { | ||
| 53 | (waker.vtable(), waker.data()) | ||
| 54 | } | ||
| 55 | }; | ||
| 56 | |||
| 57 | if vtable != &VTABLE { | ||
| 42 | panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") | 58 | panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") |
| 43 | } | 59 | } |
| 44 | |||
| 45 | // safety: our wakers are always created with `TaskRef::as_ptr` | 60 | // safety: our wakers are always created with `TaskRef::as_ptr` |
| 46 | unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) } | 61 | unsafe { TaskRef::from_ptr(data as *const TaskHeader) } |
| 47 | } | ||
| 48 | |||
| 49 | struct WakerHack { | ||
| 50 | data: *const (), | ||
| 51 | vtable: &'static RawWakerVTable, | ||
| 52 | } | 62 | } |
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 2c2441dd5..348cc7dc4 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] | 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] |
| 2 | 2 | ||
| 3 | use std::boxed::Box; | 3 | use std::boxed::Box; |
| 4 | use std::future::poll_fn; | 4 | use std::future::poll_fn; |
