diff options
| author | James Munns <[email protected]> | 2025-04-01 18:35:41 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-09-11 14:45:06 +0200 |
| commit | 8c70aafd4be63ff7af895f116444fb81438ae6e0 (patch) | |
| tree | 9d34e4eebf29b9a6e32b477691721ff30b737c88 /embassy-executor/src/raw/run_queue_drs_atomics.rs | |
| parent | 1f50e4d496458dbc7fccd9d028217ebfa7735471 (diff) | |
Make some things more consistent
Diffstat (limited to 'embassy-executor/src/raw/run_queue_drs_atomics.rs')
| -rw-r--r-- | embassy-executor/src/raw/run_queue_drs_atomics.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/embassy-executor/src/raw/run_queue_drs_atomics.rs b/embassy-executor/src/raw/run_queue_drs_atomics.rs index 69b7b3bf0..047265954 100644 --- a/embassy-executor/src/raw/run_queue_drs_atomics.rs +++ b/embassy-executor/src/raw/run_queue_drs_atomics.rs | |||
| @@ -2,6 +2,29 @@ use super::{TaskHeader, TaskRef}; | |||
| 2 | use cordyceps::{SortedList, TransferStack}; | 2 | use cordyceps::{SortedList, TransferStack}; |
| 3 | use core::future::{Future, poll_fn}; | 3 | use core::future::{Future, poll_fn}; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | use core::ptr::{addr_of_mut, NonNull}; | ||
| 6 | use cordyceps::sorted_list::Links; | ||
| 7 | use cordyceps::Linked; | ||
| 8 | |||
| 9 | pub(crate) type RunQueueItem = Links<TaskHeader>; | ||
| 10 | |||
| 11 | unsafe impl Linked<Links<TaskHeader>> for super::TaskHeader { | ||
| 12 | type Handle = TaskRef; | ||
| 13 | |||
| 14 | fn into_ptr(r: Self::Handle) -> NonNull<Self> { | ||
| 15 | r.ptr.cast() | ||
| 16 | } | ||
| 17 | |||
| 18 | unsafe fn from_ptr(ptr: NonNull<Self>) -> Self::Handle { | ||
| 19 | let ptr: NonNull<TaskHeader> = ptr; | ||
| 20 | TaskRef { ptr } | ||
| 21 | } | ||
| 22 | |||
| 23 | unsafe fn links(ptr: NonNull<Self>) -> NonNull<Links<TaskHeader>> { | ||
| 24 | let ptr: *mut TaskHeader = ptr.as_ptr(); | ||
| 25 | NonNull::new_unchecked(addr_of_mut!((*ptr).run_queue_item)) | ||
| 26 | } | ||
| 27 | } | ||
| 5 | 28 | ||
| 6 | /// Atomic task queue using a very, very simple lock-free linked-list queue: | 29 | /// Atomic task queue using a very, very simple lock-free linked-list queue: |
| 7 | /// | 30 | /// |
| @@ -39,10 +62,10 @@ impl RunQueue { | |||
| 39 | /// NOTE: It is OK for `on_task` to enqueue more tasks. In this case they're left in the queue | 62 | /// NOTE: It is OK for `on_task` to enqueue more tasks. In this case they're left in the queue |
| 40 | /// and will be processed by the *next* call to `dequeue_all`, *not* the current one. | 63 | /// and will be processed by the *next* call to `dequeue_all`, *not* the current one. |
| 41 | pub(crate) fn dequeue_all(&self, on_task: impl Fn(TaskRef)) { | 64 | pub(crate) fn dequeue_all(&self, on_task: impl Fn(TaskRef)) { |
| 42 | let mut sorted = SortedList::<TaskHeader>::new(|lhs, rhs| unsafe { | 65 | // SAFETY: `deadline` can only be set through the `Deadline` interface, which |
| 43 | // TODO: Do we need any kind of access control here? Not if we say that | 66 | // only allows access to this value while the given task is being polled. |
| 44 | // tasks can only set their own priority, which they can't do if we're in | 67 | // This acts as mutual exclusion for access. |
| 45 | // the scheduler | 68 | let mut sorted = SortedList::<TaskHeader>::new_custom(|lhs, rhs| unsafe { |
| 46 | lhs.deadline.get().cmp(&rhs.deadline.get()) | 69 | lhs.deadline.get().cmp(&rhs.deadline.get()) |
| 47 | }); | 70 | }); |
| 48 | 71 | ||
