aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
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}