aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/spawner.rs
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-12-16 17:24:17 +0100
committerDániel Buga <[email protected]>2024-12-16 17:29:07 +0100
commitb47a631abf0c200c3b29b8e4ec199421835a0525 (patch)
tree4eacf2103588ac1b1df52f6fe233fa787715d78d /embassy-executor/src/spawner.rs
parentb44ef5ccb40d6b778e623e6e68a234c2e0615d25 (diff)
Rely on atomic load-store on all targets
Diffstat (limited to 'embassy-executor/src/spawner.rs')
-rw-r--r--embassy-executor/src/spawner.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs
index bc243bee7..16347ad71 100644
--- a/embassy-executor/src/spawner.rs
+++ b/embassy-executor/src/spawner.rs
@@ -1,6 +1,7 @@
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::sync::atomic::Ordering;
4use core::task::Poll; 5use core::task::Poll;
5 6
6use super::raw; 7use super::raw;
@@ -92,9 +93,13 @@ impl Spawner {
92 pub async fn for_current_executor() -> Self { 93 pub async fn for_current_executor() -> Self {
93 poll_fn(|cx| { 94 poll_fn(|cx| {
94 let task = raw::task_from_waker(cx.waker()); 95 let task = raw::task_from_waker(cx.waker());
95 let executor = raw::state::locked(|l| { 96 let executor = unsafe {
96 unsafe { task.header().executor.get(l).as_ref().unwrap_unchecked() } 97 task.header()
97 }); 98 .executor
99 .load(Ordering::Relaxed)
100 .as_ref()
101 .unwrap_unchecked()
102 };
98 let executor = unsafe { raw::Executor::wrap(executor) }; 103 let executor = unsafe { raw::Executor::wrap(executor) };
99 Poll::Ready(Self::new(executor)) 104 Poll::Ready(Self::new(executor))
100 }) 105 })
@@ -166,9 +171,13 @@ impl SendSpawner {
166 pub async fn for_current_executor() -> Self { 171 pub async fn for_current_executor() -> Self {
167 poll_fn(|cx| { 172 poll_fn(|cx| {
168 let task = raw::task_from_waker(cx.waker()); 173 let task = raw::task_from_waker(cx.waker());
169 let executor = raw::state::locked(|l| { 174 let executor = unsafe {
170 unsafe { task.header().executor.get(l).as_ref().unwrap_unchecked() } 175 task.header()
171 }); 176 .executor
177 .load(Ordering::Relaxed)
178 .as_ref()
179 .unwrap_unchecked()
180 };
172 Poll::Ready(Self::new(executor)) 181 Poll::Ready(Self::new(executor))
173 }) 182 })
174 .await 183 .await