aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/spawner.rs
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2023-03-20 16:20:51 -0500
committerGrant Miller <[email protected]>2023-03-20 17:08:15 -0500
commit41d558a5f40bbea865f2ba0899b34baed9c1c0d1 (patch)
treedca856adc805075e7db31c7cf803ef7980e422d2 /embassy-executor/src/spawner.rs
parentb6663a013f8632cefbc6d6ab9a9aa7afbcd1314b (diff)
executor: Allow TaskStorage to auto-implement `Sync`
Diffstat (limited to 'embassy-executor/src/spawner.rs')
-rw-r--r--embassy-executor/src/spawner.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs
index 7c0a0183c..2b6224045 100644
--- a/embassy-executor/src/spawner.rs
+++ b/embassy-executor/src/spawner.rs
@@ -92,6 +92,7 @@ impl Spawner {
92 poll_fn(|cx| { 92 poll_fn(|cx| {
93 let task = raw::task_from_waker(cx.waker()); 93 let task = raw::task_from_waker(cx.waker());
94 let executor = unsafe { task.header().executor.get().unwrap_unchecked() }; 94 let executor = unsafe { task.header().executor.get().unwrap_unchecked() };
95 let executor = unsafe { raw::Executor::wrap(executor) };
95 Poll::Ready(Self::new(executor)) 96 Poll::Ready(Self::new(executor))
96 }) 97 })
97 .await 98 .await
@@ -130,9 +131,7 @@ impl Spawner {
130 /// spawner to other threads, but the spawner loses the ability to spawn 131 /// spawner to other threads, but the spawner loses the ability to spawn
131 /// non-Send tasks. 132 /// non-Send tasks.
132 pub fn make_send(&self) -> SendSpawner { 133 pub fn make_send(&self) -> SendSpawner {
133 SendSpawner { 134 SendSpawner::new(&self.executor.inner)
134 executor: self.executor,
135 }
136 } 135 }
137} 136}
138 137
@@ -145,14 +144,11 @@ impl Spawner {
145/// If you want to spawn non-Send tasks, use [Spawner]. 144/// If you want to spawn non-Send tasks, use [Spawner].
146#[derive(Copy, Clone)] 145#[derive(Copy, Clone)]
147pub struct SendSpawner { 146pub struct SendSpawner {
148 executor: &'static raw::Executor, 147 executor: &'static raw::SyncExecutor,
149} 148}
150 149
151unsafe impl Send for SendSpawner {}
152unsafe impl Sync for SendSpawner {}
153
154impl SendSpawner { 150impl SendSpawner {
155 pub(crate) fn new(executor: &'static raw::Executor) -> Self { 151 pub(crate) fn new(executor: &'static raw::SyncExecutor) -> Self {
156 Self { executor } 152 Self { executor }
157 } 153 }
158 154