aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/spawner.rs
diff options
context:
space:
mode:
authorMathias <[email protected]>2023-02-13 14:55:15 +0100
committerMathias <[email protected]>2023-02-13 14:55:15 +0100
commit218b44652c149f895919b606a660b6eff30e8177 (patch)
tree5f985f6edd12926a6f374c17a3a0c3a4226088e7 /embassy-executor/src/spawner.rs
parent86113e199f37fe0888979608a08bfdaf21bff19a (diff)
parent41a563aae3e474955892b27487e185f5f486f525 (diff)
Rebase on master
Diffstat (limited to 'embassy-executor/src/spawner.rs')
-rw-r--r--embassy-executor/src/spawner.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs
index 400d973ff..7c0a0183c 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,
@@ -90,10 +89,10 @@ impl Spawner {
90 /// 89 ///
91 /// Panics if the current executor is not an Embassy executor. 90 /// Panics if the current executor is not an Embassy executor.
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| {
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 = unsafe { task.header().executor.get().unwrap_unchecked() };
96 Poll::Ready(Self::new(&*executor)) 95 Poll::Ready(Self::new(executor))
97 }) 96 })
98 .await 97 .await
99 } 98 }
@@ -166,10 +165,10 @@ impl SendSpawner {
166 /// 165 ///
167 /// Panics if the current executor is not an Embassy executor. 166 /// Panics if the current executor is not an Embassy executor.
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| {
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 = unsafe { task.header().executor.get().unwrap_unchecked() };
172 Poll::Ready(Self::new(&*executor)) 171 Poll::Ready(Self::new(executor))
173 }) 172 })
174 .await 173 .await
175 } 174 }