aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/run_queue.rs
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2023-04-02 14:11:31 -0500
committerGrant Miller <[email protected]>2023-04-05 13:23:12 -0500
commit8290236ed64435453a9c028c95246a86371bd4ce (patch)
treed52e6d3f3f742cfb620432f715a8786a56e97a78 /embassy-executor/src/raw/run_queue.rs
parenteed2b123253380d67f76bf1d0272688e8053bc9a (diff)
executor: Replace unsound critical sections with atomics
Diffstat (limited to 'embassy-executor/src/raw/run_queue.rs')
-rw-r--r--embassy-executor/src/raw/run_queue.rs18
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;
2use core::ptr::NonNull; 2use core::ptr::NonNull;
3 3
4use atomic_polyfill::{AtomicPtr, Ordering}; 4use atomic_polyfill::{AtomicPtr, Ordering};
5use critical_section::CriticalSection;
6 5
7use super::{TaskHeader, TaskRef}; 6use 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.