aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/waker.rs
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2023-01-29 12:55:06 -0600
committerGrant Miller <[email protected]>2023-01-29 15:52:13 -0600
commit48e1aab762e902ee0a132602d3c2f9ec0551cd6b (patch)
tree1b504ef8ffcd62dd5071e90158efd28172238648 /embassy-executor/src/raw/waker.rs
parent7e251a25509a02f9388a8352522e1a279ad857b1 (diff)
executor: Replace `NonNull<TaskHeader>` with `TaskRef`
Diffstat (limited to 'embassy-executor/src/raw/waker.rs')
-rw-r--r--embassy-executor/src/raw/waker.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index 5765259f2..400b37fa9 100644
--- a/embassy-executor/src/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -1,8 +1,7 @@
1use core::mem; 1use core::mem;
2use core::ptr::NonNull;
3use core::task::{RawWaker, RawWakerVTable, Waker}; 2use core::task::{RawWaker, RawWakerVTable, Waker};
4 3
5use super::{wake_task, TaskHeader}; 4use super::{wake_task, TaskHeader, TaskRef};
6 5
7const VTABLE: RawWakerVTable = RawWakerVTable::new(clone, wake, wake, drop); 6const VTABLE: RawWakerVTable = RawWakerVTable::new(clone, wake, wake, drop);
8 7
@@ -11,14 +10,14 @@ unsafe fn clone(p: *const ()) -> RawWaker {
11} 10}
12 11
13unsafe fn wake(p: *const ()) { 12unsafe fn wake(p: *const ()) {
14 wake_task(NonNull::new_unchecked(p as *mut TaskHeader)) 13 wake_task(TaskRef::from_ptr(p as *const TaskHeader))
15} 14}
16 15
17unsafe fn drop(_: *const ()) { 16unsafe fn drop(_: *const ()) {
18 // nop 17 // nop
19} 18}
20 19
21pub(crate) unsafe fn from_task(p: NonNull<TaskHeader>) -> Waker { 20pub(crate) unsafe fn from_task(p: TaskRef) -> Waker {
22 Waker::from_raw(RawWaker::new(p.as_ptr() as _, &VTABLE)) 21 Waker::from_raw(RawWaker::new(p.as_ptr() as _, &VTABLE))
23} 22}
24 23
@@ -33,7 +32,7 @@ pub(crate) unsafe fn from_task(p: NonNull<TaskHeader>) -> Waker {
33/// # Panics 32/// # Panics
34/// 33///
35/// Panics if the waker is not created by the Embassy executor. 34/// Panics if the waker is not created by the Embassy executor.
36pub fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> { 35pub fn task_from_waker(waker: &Waker) -> TaskRef {
37 // safety: OK because WakerHack has the same layout as Waker. 36 // safety: OK because WakerHack has the same layout as Waker.
38 // This is not really guaranteed because the structs are `repr(Rust)`, it is 37 // This is not really guaranteed because the structs are `repr(Rust)`, it is
39 // indeed the case in the current implementation. 38 // indeed the case in the current implementation.
@@ -43,8 +42,8 @@ pub fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> {
43 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") 42 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
44 } 43 }
45 44
46 // safety: we never create a waker with a null data pointer. 45 // safety: our wakers are always created with `TaskRef::as_ptr`
47 unsafe { NonNull::new_unchecked(hack.data as *mut TaskHeader) } 46 unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) }
48} 47}
49 48
50struct WakerHack { 49struct WakerHack {