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-driver/CHANGELOG.md | 15 --- embassy-time-queue-driver/Cargo.toml | 58 --------- embassy-time-queue-driver/README.md | 8 -- embassy-time-queue-driver/build.rs | 1 - embassy-time-queue-driver/src/lib.rs | 20 --- embassy-time-queue-driver/src/queue_generic.rs | 146 ---------------------- embassy-time-queue-driver/src/queue_integrated.rs | 89 ------------- 7 files changed, 337 deletions(-) delete mode 100644 embassy-time-queue-driver/CHANGELOG.md delete mode 100644 embassy-time-queue-driver/Cargo.toml delete mode 100644 embassy-time-queue-driver/README.md delete mode 100644 embassy-time-queue-driver/build.rs delete mode 100644 embassy-time-queue-driver/src/lib.rs delete mode 100644 embassy-time-queue-driver/src/queue_generic.rs delete mode 100644 embassy-time-queue-driver/src/queue_integrated.rs (limited to 'embassy-time-queue-driver') diff --git a/embassy-time-queue-driver/CHANGELOG.md b/embassy-time-queue-driver/CHANGELOG.md deleted file mode 100644 index 46d00c87d..000000000 --- a/embassy-time-queue-driver/CHANGELOG.md +++ /dev/null @@ -1,15 +0,0 @@ -# Changelog for embassy-time-queue-driver - -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.2.0 - 2024-12-18 - -- Added `generic-queue-N` features. -- Added `embassy_time_queue_driver::Queue` struct which uses integrated or a generic storage (configured using `generic-queue-N`). - -## 0.1.0 - 2024-01-11 - -Initial release diff --git a/embassy-time-queue-driver/Cargo.toml b/embassy-time-queue-driver/Cargo.toml deleted file mode 100644 index 990393cc0..000000000 --- a/embassy-time-queue-driver/Cargo.toml +++ /dev/null @@ -1,58 +0,0 @@ -[package] -name = "embassy-time-queue-driver" -version = "0.2.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-driver" -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-driver-v$VERSION/embassy-time-queue-driver/src/" -src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time-queue-driver/src/" -target = "x86_64-unknown-linux-gnu" diff --git a/embassy-time-queue-driver/README.md b/embassy-time-queue-driver/README.md deleted file mode 100644 index b9fb12d94..000000000 --- a/embassy-time-queue-driver/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# embassy-time-queue-driver - -This crate contains the driver trait used by the [`embassy-time`](https://crates.io/crates/embassy-time) timer queue. - -You should rarely need to use this crate directly. Only use it when implementing your own timer queue. - -There is two timer queue implementations, one in `embassy-time` enabled by the `generic-queue` feature, and -another in `embassy-executor` enabled by the `integrated-timers` feature. diff --git a/embassy-time-queue-driver/build.rs b/embassy-time-queue-driver/build.rs deleted file mode 100644 index f328e4d9d..000000000 --- a/embassy-time-queue-driver/build.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/embassy-time-queue-driver/src/lib.rs b/embassy-time-queue-driver/src/lib.rs deleted file mode 100644 index 72453f0ea..000000000 --- a/embassy-time-queue-driver/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![no_std] -#![doc = include_str!("../README.md")] -#![warn(missing_docs)] - -//! This crate is an implementation detail of `embassy-time-driver`. -//! -//! As a HAL user, you should not need to depend on this crate directly. -//! -//! 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`. - -#[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-driver/src/queue_generic.rs b/embassy-time-queue-driver/src/queue_generic.rs deleted file mode 100644 index 232035bc6..000000000 --- a/embassy-time-queue-driver/src/queue_generic.rs +++ /dev/null @@ -1,146 +0,0 @@ -//! 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-driver/src/queue_integrated.rs b/embassy-time-queue-driver/src/queue_integrated.rs deleted file mode 100644 index 246cf1d63..000000000 --- a/embassy-time-queue-driver/src/queue_integrated.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! 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