diff options
| author | Dániel Buga <[email protected]> | 2024-12-08 23:07:35 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-12-10 21:31:42 +0100 |
| commit | dc18ee29a0f93ce34892731ee0580a3e9e3f2298 (patch) | |
| tree | 3273557f5da8ff5ad22709b3e68c6bfe30914782 | |
| parent | 12f58fbcfd3f10b43795936127a890c6a0f8f280 (diff) | |
Do not access task header
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 6 | ||||
| -rw-r--r-- | embassy-executor/src/raw/timer_queue.rs | 14 |
2 files changed, 12 insertions, 8 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 80bd49bad..f9c6509f1 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -82,6 +82,12 @@ impl TaskRef { | |||
| 82 | self.header().executor.get().map(|e| Executor::wrap(e)) | 82 | self.header().executor.get().map(|e| Executor::wrap(e)) |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | /// Returns a reference to the timer queue item. | ||
| 86 | #[cfg(feature = "integrated-timers")] | ||
| 87 | pub fn timer_queue_item(&self) -> &'static timer_queue::TimerQueueItem { | ||
| 88 | &self.header().timer_queue_item | ||
| 89 | } | ||
| 90 | |||
| 85 | /// The returned pointer is valid for the entire TaskStorage. | 91 | /// The returned pointer is valid for the entire TaskStorage. |
| 86 | pub(crate) fn as_ptr(self) -> *const TaskHeader { | 92 | pub(crate) fn as_ptr(self) -> *const TaskHeader { |
| 87 | self.ptr.as_ptr() | 93 | self.ptr.as_ptr() |
diff --git a/embassy-executor/src/raw/timer_queue.rs b/embassy-executor/src/raw/timer_queue.rs index 513397090..e0a22f4d4 100644 --- a/embassy-executor/src/raw/timer_queue.rs +++ b/embassy-executor/src/raw/timer_queue.rs | |||
| @@ -4,13 +4,14 @@ use core::cmp::min; | |||
| 4 | use super::util::SyncUnsafeCell; | 4 | use super::util::SyncUnsafeCell; |
| 5 | use super::TaskRef; | 5 | use super::TaskRef; |
| 6 | 6 | ||
| 7 | pub(crate) struct TimerQueueItem { | 7 | /// An item in the timer queue. |
| 8 | pub struct TimerQueueItem { | ||
| 8 | next: SyncUnsafeCell<Option<TaskRef>>, | 9 | next: SyncUnsafeCell<Option<TaskRef>>, |
| 9 | expires_at: SyncUnsafeCell<u64>, | 10 | expires_at: SyncUnsafeCell<u64>, |
| 10 | } | 11 | } |
| 11 | 12 | ||
| 12 | impl TimerQueueItem { | 13 | impl TimerQueueItem { |
| 13 | pub const fn new() -> Self { | 14 | pub(crate) const fn new() -> Self { |
| 14 | Self { | 15 | Self { |
| 15 | next: SyncUnsafeCell::new(None), | 16 | next: SyncUnsafeCell::new(None), |
| 16 | expires_at: SyncUnsafeCell::new(0), | 17 | expires_at: SyncUnsafeCell::new(0), |
| @@ -37,8 +38,7 @@ impl TimerQueue { | |||
| 37 | /// a new alarm for that time. | 38 | /// a new alarm for that time. |
| 38 | pub fn schedule_wake(&mut self, at: u64, p: TaskRef) -> bool { | 39 | pub fn schedule_wake(&mut self, at: u64, p: TaskRef) -> bool { |
| 39 | unsafe { | 40 | unsafe { |
| 40 | let task = p.header(); | 41 | let item = p.timer_queue_item(); |
| 41 | let item = &task.timer_queue_item; | ||
| 42 | if item.next.get().is_none() { | 42 | if item.next.get().is_none() { |
| 43 | // If not in the queue, add it and update. | 43 | // If not in the queue, add it and update. |
| 44 | let prev = self.head.replace(Some(p)); | 44 | let prev = self.head.replace(Some(p)); |
| @@ -63,8 +63,7 @@ impl TimerQueue { | |||
| 63 | let mut next_expiration = u64::MAX; | 63 | let mut next_expiration = u64::MAX; |
| 64 | 64 | ||
| 65 | self.retain(|p| { | 65 | self.retain(|p| { |
| 66 | let task = p.header(); | 66 | let item = p.timer_queue_item(); |
| 67 | let item = &task.timer_queue_item; | ||
| 68 | let expires = unsafe { item.expires_at.get() }; | 67 | let expires = unsafe { item.expires_at.get() }; |
| 69 | 68 | ||
| 70 | if expires <= now { | 69 | if expires <= now { |
| @@ -85,8 +84,7 @@ impl TimerQueue { | |||
| 85 | unsafe { | 84 | unsafe { |
| 86 | let mut prev = &self.head; | 85 | let mut prev = &self.head; |
| 87 | while let Some(p) = prev.get() { | 86 | while let Some(p) = prev.get() { |
| 88 | let task = p.header(); | 87 | let item = p.timer_queue_item(); |
| 89 | let item = &task.timer_queue_item; | ||
| 90 | if f(p) { | 88 | if f(p) { |
| 91 | // Skip to next | 89 | // Skip to next |
| 92 | prev = &item.next; | 90 | prev = &item.next; |
