From ab8ca3f126447edb3a9eb06aa6fd6cd394219c17 Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Fri, 20 Dec 2024 12:45:24 +0100 Subject: Rename ETQD, bump date --- embassy-time-queue-utils/CHANGELOG.md | 10 ++ embassy-time-queue-utils/Cargo.toml | 58 +++++++++ embassy-time-queue-utils/README.md | 8 ++ embassy-time-queue-utils/build.rs | 1 + embassy-time-queue-utils/src/lib.rs | 13 ++ embassy-time-queue-utils/src/queue_generic.rs | 146 +++++++++++++++++++++++ embassy-time-queue-utils/src/queue_integrated.rs | 89 ++++++++++++++ 7 files changed, 325 insertions(+) create mode 100644 embassy-time-queue-utils/CHANGELOG.md create mode 100644 embassy-time-queue-utils/Cargo.toml create mode 100644 embassy-time-queue-utils/README.md create mode 100644 embassy-time-queue-utils/build.rs create mode 100644 embassy-time-queue-utils/src/lib.rs create mode 100644 embassy-time-queue-utils/src/queue_generic.rs create mode 100644 embassy-time-queue-utils/src/queue_integrated.rs (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/CHANGELOG.md b/embassy-time-queue-utils/CHANGELOG.md new file mode 100644 index 000000000..ae4714f62 --- /dev/null +++ b/embassy-time-queue-utils/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog for embassy-time-queue-utils + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## 0.1.0 - 2024-01-11 + +Initial release diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml new file mode 100644 index 000000000..48be12118 --- /dev/null +++ b/embassy-time-queue-utils/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "embassy-time-queue-utils" +version = "0.1.0" +edition = "2021" +description = "Timer queue driver trait for embassy-time" +repository = "https://github.com/embassy-rs/embassy" +documentation = "https://docs.embassy.dev/embassy-time-queue-utils" +readme = "README.md" +license = "MIT OR Apache-2.0" +categories = [ + "embedded", + "no-std", + "concurrency", + "asynchronous", +] + +# Prevent multiple copies of this crate in the same binary. +# Needed because different copies might get different tick rates, causing +# wrong delays if the time driver is using one copy and user code is using another. +# This is especially common when mixing crates from crates.io and git. +links = "embassy-time-queue" + +[dependencies] +heapless = "0.8" +embassy-executor = { version = "0.7.0", path = "../embassy-executor" } + +[features] +#! ### Generic Queue + +#! By default this crate uses a timer queue implementation that is faster but depends on `embassy-executor`. +#! It will panic if you try to await any timer when using another executor. +#! +#! Alternatively, you can choose to use a "generic" timer queue implementation that works on any executor. +#! To enable it, enable any of the features below. +#! +#! The features also set how many timers are used for the generic queue. At most one +#! `generic-queue-*` feature can be enabled. If none is enabled, a default of 64 timers is used. +#! +#! When using embassy-time-queue-driver from libraries, you should *not* enable any `generic-queue-*` feature, to allow the +#! end user to pick. + +## Generic Queue with 8 timers +generic-queue-8 = ["_generic-queue"] +## Generic Queue with 16 timers +generic-queue-16 = ["_generic-queue"] +## Generic Queue with 32 timers +generic-queue-32 = ["_generic-queue"] +## Generic Queue with 64 timers +generic-queue-64 = ["_generic-queue"] +## Generic Queue with 128 timers +generic-queue-128 = ["_generic-queue"] + +_generic-queue = [] + +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-queue-utils-v$VERSION/embassy-time-queue-utils/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time-queue-utils/src/" +target = "x86_64-unknown-linux-gnu" diff --git a/embassy-time-queue-utils/README.md b/embassy-time-queue-utils/README.md new file mode 100644 index 000000000..36461f1cb --- /dev/null +++ b/embassy-time-queue-utils/README.md @@ -0,0 +1,8 @@ +# embassy-time-queue-utils + +This crate contains timer queues to help implementing an [`embassy-time-driver`](https://crates.io/crates/embassy-time-driver). + +As a HAL user, you should not need to depend on this crate. + +As a HAL implementer, you need to depend on this crate if you want to implement a time driver, +but how you should do so is documented in `embassy-time-driver`. diff --git a/embassy-time-queue-utils/build.rs b/embassy-time-queue-utils/build.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/embassy-time-queue-utils/build.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/embassy-time-queue-utils/src/lib.rs b/embassy-time-queue-utils/src/lib.rs new file mode 100644 index 000000000..a6f66913f --- /dev/null +++ b/embassy-time-queue-utils/src/lib.rs @@ -0,0 +1,13 @@ +#![no_std] +#![doc = include_str!("../README.md")] +#![warn(missing_docs)] + +#[cfg(feature = "_generic-queue")] +pub mod queue_generic; +#[cfg(not(feature = "_generic-queue"))] +pub mod queue_integrated; + +#[cfg(feature = "_generic-queue")] +pub use queue_generic::Queue; +#[cfg(not(feature = "_generic-queue"))] +pub use queue_integrated::Queue; diff --git a/embassy-time-queue-utils/src/queue_generic.rs b/embassy-time-queue-utils/src/queue_generic.rs new file mode 100644 index 000000000..232035bc6 --- /dev/null +++ b/embassy-time-queue-utils/src/queue_generic.rs @@ -0,0 +1,146 @@ +//! Generic timer queue implementations. +//! +//! Time queue drivers may use this to simplify their implementation. + +use core::cmp::{min, Ordering}; +use core::task::Waker; + +use heapless::Vec; + +#[derive(Debug)] +struct Timer { + at: u64, + waker: Waker, +} + +impl PartialEq for Timer { + fn eq(&self, other: &Self) -> bool { + self.at == other.at + } +} + +impl Eq for Timer {} + +impl PartialOrd for Timer { + fn partial_cmp(&self, other: &Self) -> Option { + self.at.partial_cmp(&other.at) + } +} + +impl Ord for Timer { + fn cmp(&self, other: &Self) -> Ordering { + self.at.cmp(&other.at) + } +} + +/// A timer queue with a pre-determined capacity. +pub struct ConstGenericQueue { + queue: Vec, +} + +impl ConstGenericQueue { + /// Creates a new timer queue. + pub const fn new() -> Self { + Self { queue: Vec::new() } + } + + /// Schedules a task to run at a specific time, and returns whether any changes were made. + /// + /// If this function returns `true`, the called should find the next expiration time and set + /// a new alarm for that time. + pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool { + self.queue + .iter_mut() + .find(|timer| timer.waker.will_wake(waker)) + .map(|timer| { + if timer.at > at { + timer.at = at; + true + } else { + false + } + }) + .unwrap_or_else(|| { + let mut timer = Timer { + waker: waker.clone(), + at, + }; + + loop { + match self.queue.push(timer) { + Ok(()) => break, + Err(e) => timer = e, + } + + self.queue.pop().unwrap().waker.wake(); + } + + true + }) + } + + /// Dequeues expired timers and returns the next alarm time. + pub fn next_expiration(&mut self, now: u64) -> u64 { + let mut next_alarm = u64::MAX; + + let mut i = 0; + while i < self.queue.len() { + let timer = &self.queue[i]; + if timer.at <= now { + let timer = self.queue.swap_remove(i); + timer.waker.wake(); + } else { + next_alarm = min(next_alarm, timer.at); + i += 1; + } + } + + next_alarm + } +} + +#[cfg(feature = "generic-queue-8")] +const QUEUE_SIZE: usize = 8; +#[cfg(feature = "generic-queue-16")] +const QUEUE_SIZE: usize = 16; +#[cfg(feature = "generic-queue-32")] +const QUEUE_SIZE: usize = 32; +#[cfg(feature = "generic-queue-64")] +const QUEUE_SIZE: usize = 64; +#[cfg(feature = "generic-queue-128")] +const QUEUE_SIZE: usize = 128; +#[cfg(not(any( + feature = "generic-queue-8", + feature = "generic-queue-16", + feature = "generic-queue-32", + feature = "generic-queue-64", + feature = "generic-queue-128" +)))] +const QUEUE_SIZE: usize = 64; + +/// A timer queue with a pre-determined capacity. +pub struct Queue { + queue: ConstGenericQueue, +} + +impl Queue { + /// Creates a new timer queue. + pub const fn new() -> Self { + Self { + queue: ConstGenericQueue::new(), + } + } + + /// Schedules a task to run at a specific time, and returns whether any changes were made. + /// + /// If this function returns `true`, the called should find the next expiration time and set + /// a new alarm for that time. + pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool { + self.queue.schedule_wake(at, waker) + } + + /// Dequeues expired timers and returns the next alarm time. + pub fn next_expiration(&mut self, now: u64) -> u64 { + self.queue.next_expiration(now) + } +} diff --git a/embassy-time-queue-utils/src/queue_integrated.rs b/embassy-time-queue-utils/src/queue_integrated.rs new file mode 100644 index 000000000..246cf1d63 --- /dev/null +++ b/embassy-time-queue-utils/src/queue_integrated.rs @@ -0,0 +1,89 @@ +//! Timer queue operations. +use core::cell::Cell; +use core::cmp::min; +use core::task::Waker; + +use embassy_executor::raw::TaskRef; + +/// A timer queue, with items integrated into tasks. +pub struct Queue { + head: Cell>, +} + +impl Queue { + /// Creates a new timer queue. + pub const fn new() -> Self { + Self { head: Cell::new(None) } + } + + /// Schedules a task to run at a specific time. + /// + /// If this function returns `true`, the called should find the next expiration time and set + /// a new alarm for that time. + pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool { + let task = embassy_executor::raw::task_from_waker(waker); + let item = task.timer_queue_item(); + if item.next.get().is_none() { + // If not in the queue, add it and update. + let prev = self.head.replace(Some(task)); + item.next.set(if prev.is_none() { + Some(unsafe { TaskRef::dangling() }) + } else { + prev + }); + item.expires_at.set(at); + true + } else if at <= item.expires_at.get() { + // If expiration is sooner than previously set, update. + item.expires_at.set(at); + true + } else { + // Task does not need to be updated. + false + } + } + + /// Dequeues expired timers and returns the next alarm time. + /// + /// The provided callback will be called for each expired task. Tasks that never expire + /// will be removed, but the callback will not be called. + pub fn next_expiration(&mut self, now: u64) -> u64 { + let mut next_expiration = u64::MAX; + + self.retain(|p| { + let item = p.timer_queue_item(); + let expires = item.expires_at.get(); + + if expires <= now { + // Timer expired, process task. + embassy_executor::raw::wake_task(p); + false + } else { + // Timer didn't yet expire, or never expires. + next_expiration = min(next_expiration, expires); + expires != u64::MAX + } + }); + + next_expiration + } + + fn retain(&self, mut f: impl FnMut(TaskRef) -> bool) { + let mut prev = &self.head; + while let Some(p) = prev.get() { + if unsafe { p == TaskRef::dangling() } { + // prev was the last item, stop + break; + } + let item = p.timer_queue_item(); + if f(p) { + // Skip to next + prev = &item.next; + } else { + // Remove it + prev.set(item.next.get()); + item.next.set(None); + } + } + } +} -- cgit From 98595f659c309703aab411b6b3be7579b6e93c5d Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Mon, 28 Jul 2025 15:37:34 +0200 Subject: `embassy-time`: add missing `Debug` & `defmt::Format` derives `defmt::Format` is *not* implemented for `MockDriver` and `InnerMockDriver` because the former contains the latter and the latter is using `Queue` from `embassy-time-queue-utils` which so far does not have a `defmt` dependency. since this is just a mock driver it shouldn't be relevant if it has no `defmt::Format` impl. --- embassy-time-queue-utils/src/lib.rs | 1 + embassy-time-queue-utils/src/queue_generic.rs | 2 ++ embassy-time-queue-utils/src/queue_integrated.rs | 1 + 3 files changed, 4 insertions(+) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/src/lib.rs b/embassy-time-queue-utils/src/lib.rs index a6f66913f..08e186432 100644 --- a/embassy-time-queue-utils/src/lib.rs +++ b/embassy-time-queue-utils/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![doc = include_str!("../README.md")] #![warn(missing_docs)] +#![deny(missing_debug_implementations)] #[cfg(feature = "_generic-queue")] pub mod queue_generic; diff --git a/embassy-time-queue-utils/src/queue_generic.rs b/embassy-time-queue-utils/src/queue_generic.rs index 232035bc6..bff7a4735 100644 --- a/embassy-time-queue-utils/src/queue_generic.rs +++ b/embassy-time-queue-utils/src/queue_generic.rs @@ -34,6 +34,7 @@ impl Ord for Timer { } /// A timer queue with a pre-determined capacity. +#[derive(Debug)] pub struct ConstGenericQueue { queue: Vec, } @@ -119,6 +120,7 @@ const QUEUE_SIZE: usize = 128; const QUEUE_SIZE: usize = 64; /// A timer queue with a pre-determined capacity. +#[derive(Debug)] pub struct Queue { queue: ConstGenericQueue, } diff --git a/embassy-time-queue-utils/src/queue_integrated.rs b/embassy-time-queue-utils/src/queue_integrated.rs index 246cf1d63..748cd7843 100644 --- a/embassy-time-queue-utils/src/queue_integrated.rs +++ b/embassy-time-queue-utils/src/queue_integrated.rs @@ -6,6 +6,7 @@ use core::task::Waker; use embassy_executor::raw::TaskRef; /// A timer queue, with items integrated into tasks. +#[derive(Debug)] pub struct Queue { head: Cell>, } -- cgit From 3f1ddaf60e8fe2ce330ab7d5fefdf4814348df9e Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 31 Jul 2025 10:32:01 +0200 Subject: chore: prepare embassy-executor 0.8 release --- embassy-time-queue-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 48be12118..fd98a1633 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -22,7 +22,7 @@ links = "embassy-time-queue" [dependencies] heapless = "0.8" -embassy-executor = { version = "0.7.0", path = "../embassy-executor" } +embassy-executor = { version = "0.8.0", path = "../embassy-executor" } [features] #! ### Generic Queue -- cgit From 59db841320df6d84e8a6f0b5de3ea5ef7dc11f6e Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 1 Aug 2025 15:17:40 +0200 Subject: fix: relax embassy-executor version requirement --- embassy-time-queue-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index fd98a1633..86a714be6 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -22,7 +22,7 @@ links = "embassy-time-queue" [dependencies] heapless = "0.8" -embassy-executor = { version = "0.8.0", path = "../embassy-executor" } +embassy-executor = { version = ">=0.7, <= 0.8", path = "../embassy-executor" } [features] #! ### Generic Queue -- cgit From e818e49d7a3c27a237bcd6d84df7971c3a02deba Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 1 Aug 2025 15:35:04 +0200 Subject: chore: Release embassy-time-queue-utils version 0.1.1 --- embassy-time-queue-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 86a714be6..0523461df 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embassy-time-queue-utils" -version = "0.1.0" +version = "0.1.1" edition = "2021" description = "Timer queue driver trait for embassy-time" repository = "https://github.com/embassy-rs/embassy" -- cgit From 0eceb08b90b1a7917db64ace80c3564d09394439 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 1 Aug 2025 21:42:23 +0200 Subject: fix: do full minor version bump for time queue utils --- embassy-time-queue-utils/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 0523461df..93fa0ce3c 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embassy-time-queue-utils" -version = "0.1.1" +version = "0.2.0" edition = "2021" description = "Timer queue driver trait for embassy-time" repository = "https://github.com/embassy-rs/embassy" @@ -22,7 +22,7 @@ links = "embassy-time-queue" [dependencies] heapless = "0.8" -embassy-executor = { version = ">=0.7, <= 0.8", path = "../embassy-executor" } +embassy-executor = { version = "0.8", path = "../embassy-executor" } [features] #! ### Generic Queue -- cgit From 74037f04933f4ec9a678e0b47fd6819e7c0489a9 Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Mon, 4 Aug 2025 00:05:25 +0200 Subject: Make TimerQueueItem opaque --- embassy-time-queue-utils/CHANGELOG.md | 8 ++ embassy-time-queue-utils/Cargo.toml | 2 +- embassy-time-queue-utils/src/lib.rs | 1 - embassy-time-queue-utils/src/queue_integrated.rs | 122 ++++++++++++++++------- 4 files changed, 93 insertions(+), 40 deletions(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/CHANGELOG.md b/embassy-time-queue-utils/CHANGELOG.md index ae4714f62..ebd6565d1 100644 --- a/embassy-time-queue-utils/CHANGELOG.md +++ b/embassy-time-queue-utils/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +- Removed the embassy-executor dependency + +## 0.2.0 - 2025-08-04 + +Bumpep embassy-executor + ## 0.1.0 - 2024-01-11 Initial release diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 93fa0ce3c..8991da66c 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -22,7 +22,7 @@ links = "embassy-time-queue" [dependencies] heapless = "0.8" -embassy-executor = { version = "0.8", path = "../embassy-executor" } +embassy-executor-timer-queue = { version = "0.1", path = "../embassy-executor-timer-queue", features = ["timer-item-size-6-words"] } [features] #! ### Generic Queue diff --git a/embassy-time-queue-utils/src/lib.rs b/embassy-time-queue-utils/src/lib.rs index 08e186432..a6f66913f 100644 --- a/embassy-time-queue-utils/src/lib.rs +++ b/embassy-time-queue-utils/src/lib.rs @@ -1,7 +1,6 @@ #![no_std] #![doc = include_str!("../README.md")] #![warn(missing_docs)] -#![deny(missing_debug_implementations)] #[cfg(feature = "_generic-queue")] pub mod queue_generic; diff --git a/embassy-time-queue-utils/src/queue_integrated.rs b/embassy-time-queue-utils/src/queue_integrated.rs index 748cd7843..2731d1ac6 100644 --- a/embassy-time-queue-utils/src/queue_integrated.rs +++ b/embassy-time-queue-utils/src/queue_integrated.rs @@ -1,16 +1,50 @@ //! Timer queue operations. use core::cell::Cell; use core::cmp::min; +use core::ptr::NonNull; use core::task::Waker; -use embassy_executor::raw::TaskRef; +use embassy_executor_timer_queue::TimerQueueItem; + +/// An item in the timer queue. +#[derive(Default)] +struct QueueItem { + /// The next item in the queue. + /// + /// If this field contains `Some`, the item is in the queue. The last item in the queue has a + /// value of `Some(dangling_pointer)` + pub next: Cell>>, + + /// The time at which this item expires. + pub expires_at: u64, + + /// The registered waker. If Some, the item is enqueued in the timer queue. + pub waker: Option, +} + +unsafe impl Sync for QueueItem {} /// A timer queue, with items integrated into tasks. -#[derive(Debug)] +/// +/// # Safety +/// +/// **This Queue is only safe when there is a single integrated queue in the system.** +/// +/// If there are multiple integrated queues, additional checks are necessary to ensure that a Waker +/// is not attempted to be enqueued in multiple queues. pub struct Queue { - head: Cell>, + head: Cell>>, } +impl core::fmt::Debug for Queue { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Queue").finish() + } +} + +unsafe impl Send for Queue {} +unsafe impl Sync for Queue {} + impl Queue { /// Creates a new timer queue. pub const fn new() -> Self { @@ -22,25 +56,41 @@ impl Queue { /// If this function returns `true`, the called should find the next expiration time and set /// a new alarm for that time. pub fn schedule_wake(&mut self, at: u64, waker: &Waker) -> bool { - let task = embassy_executor::raw::task_from_waker(waker); - let item = task.timer_queue_item(); - if item.next.get().is_none() { - // If not in the queue, add it and update. - let prev = self.head.replace(Some(task)); - item.next.set(if prev.is_none() { - Some(unsafe { TaskRef::dangling() }) - } else { - prev - }); - item.expires_at.set(at); - true - } else if at <= item.expires_at.get() { - // If expiration is sooner than previously set, update. - item.expires_at.set(at); - true - } else { - // Task does not need to be updated. - false + let item = unsafe { + // Safety: the `&mut self`, along with the Safety note of the Queue, are sufficient to + // ensure that this function creates the only mutable reference to the queue item. + TimerQueueItem::from_embassy_waker(waker) + }; + let item = unsafe { item.as_mut::() }; + match item.waker.as_ref() { + Some(_) if at <= item.expires_at => { + // If expiration is sooner than previously set, update. + item.expires_at = at; + // The waker is always stored in its own queue item, so we don't need to update it. + + // Trigger a queue update in case this item can be immediately dequeued. + true + } + Some(_) => { + // Queue item does not need to be updated, the task will be scheduled to be woken + // before the new expiration. + false + } + None => { + // If not in the queue, add it and update. + let mut item_ptr = NonNull::from(item); + let prev = self.head.replace(Some(item_ptr)); + + let item = unsafe { item_ptr.as_mut() }; + + item.expires_at = at; + item.waker = Some(waker.clone()); + item.next.set(prev); + // The default implementation doesn't care about the + // opaque payload, leave it unchanged. + + true + } } } @@ -51,33 +101,29 @@ impl Queue { pub fn next_expiration(&mut self, now: u64) -> u64 { let mut next_expiration = u64::MAX; - self.retain(|p| { - let item = p.timer_queue_item(); - let expires = item.expires_at.get(); - - if expires <= now { + self.retain(|item| { + if item.expires_at <= now { // Timer expired, process task. - embassy_executor::raw::wake_task(p); + if let Some(waker) = item.waker.take() { + waker.wake(); + } false } else { // Timer didn't yet expire, or never expires. - next_expiration = min(next_expiration, expires); - expires != u64::MAX + next_expiration = min(next_expiration, item.expires_at); + item.expires_at != u64::MAX } }); next_expiration } - fn retain(&self, mut f: impl FnMut(TaskRef) -> bool) { + fn retain(&mut self, mut f: impl FnMut(&mut QueueItem) -> bool) { let mut prev = &self.head; - while let Some(p) = prev.get() { - if unsafe { p == TaskRef::dangling() } { - // prev was the last item, stop - break; - } - let item = p.timer_queue_item(); - if f(p) { + while let Some(mut p) = prev.get() { + let mut item = unsafe { p.as_mut() }; + + if f(&mut item) { // Skip to next prev = &item.next; } else { -- cgit From 3d1ce0fb7daadf647298230b51a7fb8fbaa1feed Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Mon, 18 Aug 2025 12:51:27 +0200 Subject: Fix typo --- embassy-time-queue-utils/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/CHANGELOG.md b/embassy-time-queue-utils/CHANGELOG.md index ebd6565d1..26200503c 100644 --- a/embassy-time-queue-utils/CHANGELOG.md +++ b/embassy-time-queue-utils/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.2.0 - 2025-08-04 -Bumpep embassy-executor +Bumped embassy-executor ## 0.1.0 - 2024-01-11 -- cgit From 6a347f1f09b0076af868dcd63d9139081c92172b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 14 Aug 2025 13:36:39 +0200 Subject: feat: add semver checks and releasing to releaser * List dependencies of a crate * List dependents of a crate * Perform semver-checks of a crate * Prepare a release for a crate and all dependents * Use a single release.toml for cargo-release * Add changelogs where missing --- embassy-time-queue-utils/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/CHANGELOG.md b/embassy-time-queue-utils/CHANGELOG.md index 26200503c..510c29d58 100644 --- a/embassy-time-queue-utils/CHANGELOG.md +++ b/embassy-time-queue-utils/CHANGELOG.md @@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased + +## Unreleased - ReleaseDate - Removed the embassy-executor dependency -- cgit From 9f12852c389d65a8b2e252e027f69dfef2383736 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 15 Aug 2025 15:30:14 +0200 Subject: Read crate configs from metadata. --- embassy-time-queue-utils/Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 8991da66c..2a659548e 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -52,6 +52,12 @@ generic-queue-128 = ["_generic-queue"] _generic-queue = [] +[package.metadata.embassy] +build = [ + {target = "thumbv6m-none-eabi", features = []}, + {target = "thumbv6m-none-eabi", features = ["generic-queue-8"]}, +] + [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-queue-utils-v$VERSION/embassy-time-queue-utils/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time-queue-utils/src/" -- cgit From 83f2557eacd657070a84a9baf2da6e3aff03b2b7 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 26 Aug 2025 16:04:00 +0200 Subject: chore: prepare embassy crate releases --- embassy-time-queue-utils/CHANGELOG.md | 4 ++++ embassy-time-queue-utils/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/CHANGELOG.md b/embassy-time-queue-utils/CHANGELOG.md index 510c29d58..03d89f9a7 100644 --- a/embassy-time-queue-utils/CHANGELOG.md +++ b/embassy-time-queue-utils/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - ReleaseDate +## 0.3.0 - 2025-08-26 + +## 0.2.1 - 2025-08-26 + - Removed the embassy-executor dependency ## 0.2.0 - 2025-08-04 diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 2a659548e..e1abf1cd8 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embassy-time-queue-utils" -version = "0.2.0" +version = "0.3.0" edition = "2021" description = "Timer queue driver trait for embassy-time" repository = "https://github.com/embassy-rs/embassy" -- cgit From 55b3c5c6e8fb5e55a0e507c43db5d9ef32114f64 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 11 Sep 2025 21:27:02 +0200 Subject: ci: use devtool to build. --- embassy-time-queue-utils/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index e1abf1cd8..13da62874 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -56,6 +56,9 @@ _generic-queue = [] build = [ {target = "thumbv6m-none-eabi", features = []}, {target = "thumbv6m-none-eabi", features = ["generic-queue-8"]}, + # Xtensa builds + {group = "xtensa", build-std = ["core", "alloc"], target = "xtensa-esp32s2-none-elf", features = []}, + {group = "xtensa", build-std = ["core", "alloc"], target = "xtensa-esp32s2-none-elf", features = ["generic-queue-8"]}, ] [package.metadata.embassy_docs] -- cgit From abc8e450f936567ad42cb34b5d2a7941b206aa5d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 6 Oct 2025 22:55:38 +0200 Subject: Edition 2024. --- embassy-time-queue-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/Cargo.toml b/embassy-time-queue-utils/Cargo.toml index 13da62874..8da30c544 100644 --- a/embassy-time-queue-utils/Cargo.toml +++ b/embassy-time-queue-utils/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "embassy-time-queue-utils" version = "0.3.0" -edition = "2021" +edition = "2024" description = "Timer queue driver trait for embassy-time" repository = "https://github.com/embassy-rs/embassy" documentation = "https://docs.embassy.dev/embassy-time-queue-utils" -- cgit From 8730a013c395cf0bf4c2fa8eeb7f138288103039 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 6 Oct 2025 22:56:31 +0200 Subject: Rustfmt for edition 2024. --- embassy-time-queue-utils/src/queue_generic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-time-queue-utils') diff --git a/embassy-time-queue-utils/src/queue_generic.rs b/embassy-time-queue-utils/src/queue_generic.rs index bff7a4735..88986953d 100644 --- a/embassy-time-queue-utils/src/queue_generic.rs +++ b/embassy-time-queue-utils/src/queue_generic.rs @@ -2,7 +2,7 @@ //! //! Time queue drivers may use this to simplify their implementation. -use core::cmp::{min, Ordering}; +use core::cmp::{Ordering, min}; use core::task::Waker; use heapless::Vec; -- cgit