aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/waker.rs
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2025-12-18 09:57:52 +0100
committerDániel Buga <[email protected]>2025-12-18 09:57:52 +0100
commite62adea1f93f8eaba2f9da5ebe90e5f23a480101 (patch)
tree2fd8c45cd22a522798b1655cba19af257d5d232b /embassy-executor/src/raw/waker.rs
parente2d9adc56481e97fa490c8c3cc05bdad0dbe22e4 (diff)
executor: Add fallible from_waker getter
Diffstat (limited to 'embassy-executor/src/raw/waker.rs')
-rw-r--r--embassy-executor/src/raw/waker.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index 2706f0fdf..8416f9f93 100644
--- a/embassy-executor/src/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -32,13 +32,18 @@ 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 unwrap!(
36 try_task_from_waker(waker),
37 "Found waker not created by the Embassy executor. Unless the generic timer queue is enabled, `embassy_time::Timer` only works with the Embassy executor."
38 )
39}
40
41pub(crate) fn try_task_from_waker(waker: &Waker) -> Option<TaskRef> {
35 // make sure to compare vtable addresses. Doing `==` on the references 42 // make sure to compare vtable addresses. Doing `==` on the references
36 // will compare the contents, which is slower. 43 // will compare the contents, which is slower.
37 if waker.vtable() as *const _ != &VTABLE as *const _ { 44 if waker.vtable() as *const _ != &VTABLE as *const _ {
38 panic!( 45 return None;
39 "Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor."
40 )
41 } 46 }
42 // safety: our wakers are always created with `TaskRef::as_ptr` 47 // safety: our wakers are always created with `TaskRef::as_ptr`
43 unsafe { TaskRef::from_ptr(waker.data() as *const TaskHeader) } 48 Some(unsafe { TaskRef::from_ptr(waker.data() as *const TaskHeader) })
44} 49}