diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-06 18:01:21 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-06 18:01:21 +0000 |
| commit | f3ec6080bf9a39d9819195861e7b41e8a2081600 (patch) | |
| tree | 297b66d17c483b07b1338fa4e40fbb4c739c904f /embassy-executor/src/raw/run_queue.rs | |
| parent | 89279dcdc90c8864751fdf43c3d9dd887b7045c1 (diff) | |
| parent | 8290236ed64435453a9c028c95246a86371bd4ce (diff) | |
Merge #1332
1332: executor: Replace unsound critical sections with atomics r=Dirbaio a=GrantM11235
I couldn't figure out the correct orderings, so I just left them as SeqCst for now.
Co-authored-by: Grant Miller <[email protected]>
Diffstat (limited to 'embassy-executor/src/raw/run_queue.rs')
| -rw-r--r-- | embassy-executor/src/raw/run_queue.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/embassy-executor/src/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs index 362157535..a88174a0c 100644 --- a/embassy-executor/src/raw/run_queue.rs +++ b/embassy-executor/src/raw/run_queue.rs | |||
| @@ -2,7 +2,6 @@ use core::ptr; | |||
| 2 | use core::ptr::NonNull; | 2 | use core::ptr::NonNull; |
| 3 | 3 | ||
| 4 | use atomic_polyfill::{AtomicPtr, Ordering}; | 4 | use atomic_polyfill::{AtomicPtr, Ordering}; |
| 5 | use critical_section::CriticalSection; | ||
| 6 | 5 | ||
| 7 | use super::{TaskHeader, TaskRef}; | 6 | use super::{TaskHeader, TaskRef}; |
| 8 | 7 | ||
| @@ -46,11 +45,18 @@ impl RunQueue { | |||
| 46 | /// | 45 | /// |
| 47 | /// `item` must NOT be already enqueued in any queue. | 46 | /// `item` must NOT be already enqueued in any queue. |
| 48 | #[inline(always)] | 47 | #[inline(always)] |
| 49 | pub(crate) unsafe fn enqueue(&self, _cs: CriticalSection, task: TaskRef) -> bool { | 48 | pub(crate) unsafe fn enqueue(&self, task: TaskRef) -> bool { |
| 50 | let prev = self.head.load(Ordering::Relaxed); | 49 | let mut was_empty = false; |
| 51 | task.header().run_queue_item.next.store(prev, Ordering::Relaxed); | 50 | |
| 52 | self.head.store(task.as_ptr() as _, Ordering::Relaxed); | 51 | self.head |
| 53 | prev.is_null() | 52 | .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |prev| { |
| 53 | was_empty = prev.is_null(); | ||
| 54 | task.header().run_queue_item.next.store(prev, Ordering::Relaxed); | ||
| 55 | Some(task.as_ptr() as *mut _) | ||
| 56 | }) | ||
| 57 | .ok(); | ||
| 58 | |||
| 59 | was_empty | ||
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | /// Empty the queue, then call `on_task` for each task that was in the queue. | 62 | /// Empty the queue, then call `on_task` for each task that was in the queue. |
