aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-12-17 13:16:54 +0100
committerGitHub <[email protected]>2024-12-17 13:16:54 +0100
commit9cf037bc954cc347b5d52d90207f68090cc5b09e (patch)
treef9585a72940a2f39d53f49e73eddf6eb8e35178e /embassy-executor/src
parentd3f0294fb12e060c4a3ba557ff95766d1c3686e0 (diff)
parentfc25fca00b48630073575d14bcc713912d0b0104 (diff)
Merge pull request #3657 from embassy-rs/waker-unhack
Remove WakerHack for good.
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/waker.rs15
1 files changed, 2 insertions, 13 deletions
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index 9c70f995a..b7d57c314 100644
--- a/embassy-executor/src/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -32,22 +32,11 @@ 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 struct WakerHack {
36 data: *const (),
37 vtable: &'static RawWakerVTable,
38 }
39
40 // safety: OK because WakerHack has the same layout as Waker.
41 // This is not really guaranteed because the structs are `repr(Rust)`, it is
42 // indeed the case in the current implementation.
43 // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
44 let hack: &WakerHack = unsafe { core::mem::transmute(waker) };
45
46 // make sure to compare vtable addresses. Doing `==` on the references 35 // make sure to compare vtable addresses. Doing `==` on the references
47 // will compare the contents, which is slower. 36 // will compare the contents, which is slower.
48 if hack.vtable as *const _ != &VTABLE as *const _ { 37 if waker.vtable() as *const _ != &VTABLE as *const _ {
49 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") 38 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
50 } 39 }
51 // safety: our wakers are always created with `TaskRef::as_ptr` 40 // safety: our wakers are always created with `TaskRef::as_ptr`
52 unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) } 41 unsafe { TaskRef::from_ptr(waker.data() as *const TaskHeader) }
53} 42}