diff options
Diffstat (limited to 'embassy-executor/src/raw/timer_queue.rs')
| -rw-r--r-- | embassy-executor/src/raw/timer_queue.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/embassy-executor/src/raw/timer_queue.rs b/embassy-executor/src/raw/timer_queue.rs index dc71c95b1..59a3b43f5 100644 --- a/embassy-executor/src/raw/timer_queue.rs +++ b/embassy-executor/src/raw/timer_queue.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use core::cmp::min; | 1 | use core::cmp::min; |
| 2 | 2 | ||
| 3 | use atomic_polyfill::Ordering; | ||
| 4 | use embassy_time::Instant; | 3 | use embassy_time::Instant; |
| 5 | 4 | ||
| 6 | use super::{TaskRef, STATE_TIMER_QUEUED}; | 5 | use super::TaskRef; |
| 7 | use crate::raw::util::SyncUnsafeCell; | 6 | use crate::raw::util::SyncUnsafeCell; |
| 8 | 7 | ||
| 9 | pub(crate) struct TimerQueueItem { | 8 | pub(crate) struct TimerQueueItem { |
| @@ -32,10 +31,7 @@ impl TimerQueue { | |||
| 32 | pub(crate) unsafe fn update(&self, p: TaskRef) { | 31 | pub(crate) unsafe fn update(&self, p: TaskRef) { |
| 33 | let task = p.header(); | 32 | let task = p.header(); |
| 34 | if task.expires_at.get() != Instant::MAX { | 33 | if task.expires_at.get() != Instant::MAX { |
| 35 | let old_state = task.state.fetch_or(STATE_TIMER_QUEUED, Ordering::AcqRel); | 34 | if task.state.timer_enqueue() { |
| 36 | let is_new = old_state & STATE_TIMER_QUEUED == 0; | ||
| 37 | |||
| 38 | if is_new { | ||
| 39 | task.timer_queue_item.next.set(self.head.get()); | 35 | task.timer_queue_item.next.set(self.head.get()); |
| 40 | self.head.set(Some(p)); | 36 | self.head.set(Some(p)); |
| 41 | } | 37 | } |
| @@ -75,7 +71,7 @@ impl TimerQueue { | |||
| 75 | } else { | 71 | } else { |
| 76 | // Remove it | 72 | // Remove it |
| 77 | prev.set(task.timer_queue_item.next.get()); | 73 | prev.set(task.timer_queue_item.next.get()); |
| 78 | task.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::AcqRel); | 74 | task.state.timer_dequeue(); |
| 79 | } | 75 | } |
| 80 | } | 76 | } |
| 81 | } | 77 | } |
