aboutsummaryrefslogtreecommitdiff
path: root/embassy-time-queue-driver/src/queue_integrated.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-12-08 23:27:32 +0100
committerDániel Buga <[email protected]>2024-12-13 21:20:59 +0100
commitb268b1795fed58544c166c41842ce0d66328aa3e (patch)
tree55b6fb09f6694b5e3355d344770b36bfe1550415 /embassy-time-queue-driver/src/queue_integrated.rs
parentec96395d084d5edc8be25ddaea8547e2ebd447a6 (diff)
Merge time-driver and time-queue-driver traits, make HALs own and handle the queue.
Diffstat (limited to 'embassy-time-queue-driver/src/queue_integrated.rs')
-rw-r--r--embassy-time-queue-driver/src/queue_integrated.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/embassy-time-queue-driver/src/queue_integrated.rs b/embassy-time-queue-driver/src/queue_integrated.rs
index b905c00c3..6bb4c0c1a 100644
--- a/embassy-time-queue-driver/src/queue_integrated.rs
+++ b/embassy-time-queue-driver/src/queue_integrated.rs
@@ -1,15 +1,16 @@
1//! Timer queue operations. 1//! Timer queue operations.
2use core::cell::Cell; 2use core::cell::Cell;
3use core::cmp::min; 3use core::cmp::min;
4use core::task::Waker;
4 5
5use embassy_executor::raw::TaskRef; 6use embassy_executor::raw::TaskRef;
6 7
7/// A timer queue, with items integrated into tasks. 8/// A timer queue, with items integrated into tasks.
8pub struct TimerQueue { 9pub struct Queue {
9 head: Cell<Option<TaskRef>>, 10 head: Cell<Option<TaskRef>>,
10} 11}
11 12
12impl TimerQueue { 13impl Queue {
13 /// Creates a new timer queue. 14 /// Creates a new timer queue.
14 pub const fn new() -> Self { 15 pub const fn new() -> Self {
15 Self { head: Cell::new(None) } 16 Self { head: Cell::new(None) }
@@ -19,11 +20,12 @@ impl TimerQueue {
19 /// 20 ///
20 /// If this function returns `true`, the called should find the next expiration time and set 21 /// If this function returns `true`, the called should find the next expiration time and set
21 /// a new alarm for that time. 22 /// a new alarm for that time.
22 pub fn schedule_wake(&mut self, at: u64, p: TaskRef) -> bool { 23 pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool {
23 let item = p.timer_queue_item(); 24 let task = embassy_executor::raw::task_from_waker(waker);
25 let item = task.timer_queue_item();
24 if item.next.get().is_none() { 26 if item.next.get().is_none() {
25 // If not in the queue, add it and update. 27 // If not in the queue, add it and update.
26 let prev = self.head.replace(Some(p)); 28 let prev = self.head.replace(Some(task));
27 item.next.set(if prev.is_none() { 29 item.next.set(if prev.is_none() {
28 Some(unsafe { TaskRef::dangling() }) 30 Some(unsafe { TaskRef::dangling() })
29 } else { 31 } else {