executor: make Deadline actually private.

This commit is contained in:
Dario Nieuwenhuis 2025-09-11 15:40:33 +02:00
parent 2e21dcf2e6
commit e1209c5563
5 changed files with 13 additions and 27 deletions

View File

@ -36,7 +36,7 @@ build = [
[package.metadata.embassy_docs]
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/"
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/"
features = ["defmt"]
features = ["defmt", "scheduler-deadline"]
flavors = [
{ name = "std", target = "x86_64-unknown-linux-gnu", features = ["arch-std", "executor-thread"] },
{ name = "wasm", target = "wasm32-unknown-unknown", features = ["arch-wasm", "executor-thread"] },

View File

@ -63,8 +63,8 @@ impl Metadata {
/// Get this task's deadline.
#[cfg(feature = "scheduler-deadline")]
pub fn deadline(&self) -> &raw::Deadline {
&self.deadline
pub fn deadline(&self) -> u64 {
self.deadline.instant_ticks()
}
/// Set this task's deadline.
@ -79,7 +79,7 @@ impl Metadata {
/// This brings it back to the defaul where it's not scheduled ahead of other tasks.
#[cfg(feature = "scheduler-deadline")]
pub fn unset_deadline(&self) {
self.deadline.set(Deadline::UNSET_DEADLINE_TICKS);
self.deadline.set(Deadline::UNSET_TICKS);
}
/// Set this task's deadline `duration_ticks` in the future from when
@ -110,7 +110,7 @@ impl Metadata {
/// Returns the deadline that was set.
#[cfg(feature = "scheduler-deadline")]
pub fn increment_deadline(&self, duration_ticks: u64) {
let last = self.deadline().instant_ticks();
let last = self.deadline();
// Since ticks is a u64, saturating add is PROBABLY overly cautious, leave
// it for now, we can probably make this wrapping_add for performance

View File

@ -7,7 +7,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
/// Note: Interacting with the deadline should be done locally in a task.
/// In theory you could try to set or read the deadline from another task,
/// but that will result in weird (though not unsound) behavior.
pub struct Deadline {
pub(crate) struct Deadline {
instant_ticks_hi: AtomicU32,
instant_ticks_lo: AtomicU32,
}
@ -21,7 +21,7 @@ impl Deadline {
}
pub(crate) const fn new_unset() -> Self {
Self::new(Self::UNSET_DEADLINE_TICKS)
Self::new(Self::UNSET_TICKS)
}
pub(crate) fn set(&self, instant_ticks: u64) {
@ -31,7 +31,7 @@ impl Deadline {
}
/// Deadline value in ticks, same time base and ticks as `embassy-time`
pub fn instant_ticks(&self) -> u64 {
pub(crate) fn instant_ticks(&self) -> u64 {
let hi = self.instant_ticks_hi.load(Ordering::Relaxed) as u64;
let lo = self.instant_ticks_lo.load(Ordering::Relaxed) as u64;
@ -40,11 +40,5 @@ impl Deadline {
/// Sentinel value representing an "unset" deadline, which has lower priority
/// than any other set deadline value
pub const UNSET_DEADLINE_TICKS: u64 = u64::MAX;
/// Does the given Deadline represent an "unset" deadline?
#[inline]
pub fn is_unset(&self) -> bool {
self.instant_ticks() == Self::UNSET_DEADLINE_TICKS
}
pub(crate) const UNSET_TICKS: u64 = u64::MAX;
}

View File

@ -40,7 +40,7 @@ use core::sync::atomic::Ordering;
use core::task::{Context, Poll, Waker};
#[cfg(feature = "scheduler-deadline")]
pub use deadline::Deadline;
pub(crate) use deadline::Deadline;
use embassy_executor_timer_queue::TimerQueueItem;
#[cfg(feature = "arch-avr")]
use portable_atomic::AtomicPtr;
@ -303,11 +303,7 @@ impl<F: Future + 'static> AvailableTask<F> {
// By default, deadlines are set to the maximum value, so that any task WITH
// a set deadline will ALWAYS be scheduled BEFORE a task WITHOUT a set deadline
#[cfg(feature = "scheduler-deadline")]
self.task
.raw
.metadata
.deadline()
.set(deadline::Deadline::UNSET_DEADLINE_TICKS);
self.task.raw.metadata.unset_deadline();
let task = TaskRef::new(self.task);

View File

@ -108,12 +108,8 @@ impl RunQueue {
/// runqueue are both empty, at which point this function will return.
#[cfg(feature = "scheduler-deadline")]
pub(crate) fn dequeue_all(&self, on_task: impl Fn(TaskRef)) {
let mut sorted = SortedList::<TaskHeader>::new_with_cmp(|lhs, rhs| {
lhs.metadata
.deadline()
.instant_ticks()
.cmp(&rhs.metadata.deadline().instant_ticks())
});
let mut sorted =
SortedList::<TaskHeader>::new_with_cmp(|lhs, rhs| lhs.metadata.deadline().cmp(&rhs.metadata.deadline()));
loop {
// For each loop, grab any newly pended items