diff options
Diffstat (limited to 'embassy-executor/src/raw/timer_queue.rs')
| -rw-r--r-- | embassy-executor/src/raw/timer_queue.rs | 14 |
1 files changed, 6 insertions, 8 deletions
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; |
