aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-11-12 16:28:26 +0100
committerGitHub <[email protected]>2024-11-12 16:28:26 +0100
commitbaeb59b5b8d63ef9bb6ecada518ea8b911d2dc30 (patch)
treea27e2f99887c06f0c2279d385acbdebbe704a5c8 /embassy-executor/src
parentc66f83db702e95e010b944cdf1b0f4a9dfe771df (diff)
executor: use WakerHack unconditionally even if `nightly` feature is enabled. (#3528)
This ensures the executor compiles with all recent nightly versions, including the stable-but-with-nightly-features-enabled xtensa rustc.
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/lib.rs1
-rw-r--r--embassy-executor/src/raw/waker.rs42
2 files changed, 11 insertions, 32 deletions
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index 8e07a8b18..d816539ac 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -1,5 +1,4 @@
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#![cfg_attr(all(feature = "nightly", not(at_least_2024_09_06)), feature(waker_getters))]
3#![allow(clippy::new_without_default)] 2#![allow(clippy::new_without_default)]
4#![doc = include_str!("../README.md")] 3#![doc = include_str!("../README.md")]
5#![warn(missing_docs)] 4#![warn(missing_docs)]
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index 30b8cdd4c..d2256adfa 100644
--- a/embassy-executor/src/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -32,40 +32,20 @@ pub(crate) unsafe fn from_task(p: TaskRef) -> Waker {
32/// 32///
33/// Panics if the waker is not created by the Embassy executor. 33/// Panics if the waker is not created by the Embassy executor.
34pub fn task_from_waker(waker: &Waker) -> TaskRef { 34pub fn task_from_waker(waker: &Waker) -> TaskRef {
35 let (vtable, data) = { 35 struct WakerHack {
36 #[cfg(not(feature = "nightly"))] 36 data: *const (),
37 { 37 vtable: &'static RawWakerVTable,
38 struct WakerHack { 38 }
39 data: *const (),
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 #[cfg(not(at_least_2024_09_06))]
54 {
55 let raw_waker = waker.as_raw();
56 (raw_waker.vtable(), raw_waker.data())
57 }
58 39
59 #[cfg(at_least_2024_09_06)] 40 // safety: OK because WakerHack has the same layout as Waker.
60 { 41 // This is not really guaranteed because the structs are `repr(Rust)`, it is
61 (waker.vtable(), waker.data()) 42 // indeed the case in the current implementation.
62 } 43 // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
63 } 44 let hack: &WakerHack = unsafe { core::mem::transmute(waker) };
64 };
65 45
66 if vtable != &VTABLE { 46 if hack.vtable != &VTABLE {
67 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") 47 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
68 } 48 }
69 // safety: our wakers are always created with `TaskRef::as_ptr` 49 // safety: our wakers are always created with `TaskRef::as_ptr`
70 unsafe { TaskRef::from_ptr(data as *const TaskHeader) } 50 unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) }
71} 51}