aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/spawner.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/spawner.rs
parent7e251a25509a02f9388a8352522e1a279ad857b1 (diff)
executor: Replace `NonNull<TaskHeader>` with `TaskRef`
Diffstat (limited to 'embassy-executor/src/spawner.rs')
-rw-r--r--embassy-executor/src/spawner.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs
index 400d973ff..650ea06cb 100644
--- a/embassy-executor/src/spawner.rs
+++ b/embassy-executor/src/spawner.rs
@@ -1,7 +1,6 @@
1use core::future::poll_fn; 1use core::future::poll_fn;
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3use core::mem; 3use core::mem;
4use core::ptr::NonNull;
5use core::task::Poll; 4use core::task::Poll;
6 5
7use super::raw; 6use super::raw;
@@ -22,12 +21,12 @@ use super::raw;
22/// Once you've invoked a task function and obtained a SpawnToken, you *must* spawn it. 21/// Once you've invoked a task function and obtained a SpawnToken, you *must* spawn it.
23#[must_use = "Calling a task function does nothing on its own. You must spawn the returned SpawnToken, typically with Spawner::spawn()"] 22#[must_use = "Calling a task function does nothing on its own. You must spawn the returned SpawnToken, typically with Spawner::spawn()"]
24pub struct SpawnToken<S> { 23pub struct SpawnToken<S> {
25 raw_task: Option<NonNull<raw::TaskHeader>>, 24 raw_task: Option<raw::TaskRef>,
26 phantom: PhantomData<*mut S>, 25 phantom: PhantomData<*mut S>,
27} 26}
28 27
29impl<S> SpawnToken<S> { 28impl<S> SpawnToken<S> {
30 pub(crate) unsafe fn new(raw_task: NonNull<raw::TaskHeader>) -> Self { 29 pub(crate) unsafe fn new(raw_task: raw::TaskRef) -> Self {
31 Self { 30 Self {
32 raw_task: Some(raw_task), 31 raw_task: Some(raw_task),
33 phantom: PhantomData, 32 phantom: PhantomData,
@@ -92,7 +91,7 @@ impl Spawner {
92 pub async fn for_current_executor() -> Self { 91 pub async fn for_current_executor() -> Self {
93 poll_fn(|cx| unsafe { 92 poll_fn(|cx| unsafe {
94 let task = raw::task_from_waker(cx.waker()); 93 let task = raw::task_from_waker(cx.waker());
95 let executor = (*task.as_ptr()).executor.get(); 94 let executor = task.header().executor.get();
96 Poll::Ready(Self::new(&*executor)) 95 Poll::Ready(Self::new(&*executor))
97 }) 96 })
98 .await 97 .await
@@ -168,7 +167,7 @@ impl SendSpawner {
168 pub async fn for_current_executor() -> Self { 167 pub async fn for_current_executor() -> Self {
169 poll_fn(|cx| unsafe { 168 poll_fn(|cx| unsafe {
170 let task = raw::task_from_waker(cx.waker()); 169 let task = raw::task_from_waker(cx.waker());
171 let executor = (*task.as_ptr()).executor.get(); 170 let executor = task.header().executor.get();
172 Poll::Ready(Self::new(&*executor)) 171 Poll::Ready(Self::new(&*executor))
173 }) 172 })
174 .await 173 .await