diff options
| author | Dániel Buga <[email protected]> | 2024-12-16 15:56:55 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-12-16 16:01:08 +0100 |
| commit | b44ef5ccb40d6b778e623e6e68a234c2e0615d25 (patch) | |
| tree | 0baaa602127b047c329e351517f0fb76ec452e15 /embassy-executor/src/spawner.rs | |
| parent | 47e96beff4fc4c8dff8bf6d6a67e1d2e81c40495 (diff) | |
Fix racy access of TaskHeader::executor
Diffstat (limited to 'embassy-executor/src/spawner.rs')
| -rw-r--r-- | embassy-executor/src/spawner.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs index 271606244..bc243bee7 100644 --- a/embassy-executor/src/spawner.rs +++ b/embassy-executor/src/spawner.rs | |||
| @@ -92,7 +92,9 @@ impl Spawner { | |||
| 92 | pub async fn for_current_executor() -> Self { | 92 | pub async fn for_current_executor() -> Self { |
| 93 | poll_fn(|cx| { | 93 | poll_fn(|cx| { |
| 94 | let task = raw::task_from_waker(cx.waker()); | 94 | let task = raw::task_from_waker(cx.waker()); |
| 95 | let executor = unsafe { task.header().executor.get().unwrap_unchecked() }; | 95 | let executor = raw::state::locked(|l| { |
| 96 | unsafe { task.header().executor.get(l).as_ref().unwrap_unchecked() } | ||
| 97 | }); | ||
| 96 | let executor = unsafe { raw::Executor::wrap(executor) }; | 98 | let executor = unsafe { raw::Executor::wrap(executor) }; |
| 97 | Poll::Ready(Self::new(executor)) | 99 | Poll::Ready(Self::new(executor)) |
| 98 | }) | 100 | }) |
| @@ -164,7 +166,9 @@ impl SendSpawner { | |||
| 164 | pub async fn for_current_executor() -> Self { | 166 | pub async fn for_current_executor() -> Self { |
| 165 | poll_fn(|cx| { | 167 | poll_fn(|cx| { |
| 166 | let task = raw::task_from_waker(cx.waker()); | 168 | let task = raw::task_from_waker(cx.waker()); |
| 167 | let executor = unsafe { task.header().executor.get().unwrap_unchecked() }; | 169 | let executor = raw::state::locked(|l| { |
| 170 | unsafe { task.header().executor.get(l).as_ref().unwrap_unchecked() } | ||
| 171 | }); | ||
| 168 | Poll::Ready(Self::new(executor)) | 172 | Poll::Ready(Self::new(executor)) |
| 169 | }) | 173 | }) |
| 170 | .await | 174 | .await |
