diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-11-12 16:28:26 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-12 16:28:26 +0100 |
| commit | baeb59b5b8d63ef9bb6ecada518ea8b911d2dc30 (patch) | |
| tree | a27e2f99887c06f0c2279d385acbdebbe704a5c8 /embassy-executor/src/raw/waker.rs | |
| parent | c66f83db702e95e010b944cdf1b0f4a9dfe771df (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/raw/waker.rs')
| -rw-r--r-- | embassy-executor/src/raw/waker.rs | 42 |
1 files changed, 11 insertions, 31 deletions
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. |
| 34 | pub fn task_from_waker(waker: &Waker) -> TaskRef { | 34 | pub 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 | } |
