aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-09-11 15:40:33 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-11 15:40:33 +0200
commite1209c5563576d18c4d033b015c9a5dd6145d581 (patch)
tree431aa79f8343a7ed8eb948ad52dec5ef13f5869a
parent2e21dcf2e61440db8c56a421a87c7a6bd22424d0 (diff)
executor: make Deadline actually private.
-rw-r--r--embassy-executor/Cargo.toml2
-rw-r--r--embassy-executor/src/metadata.rs8
-rw-r--r--embassy-executor/src/raw/deadline.rs14
-rw-r--r--embassy-executor/src/raw/mod.rs8
-rw-r--r--embassy-executor/src/raw/run_queue.rs8
5 files changed, 13 insertions, 27 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index fb4c4d579..0ac666f80 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -36,7 +36,7 @@ build = [
36[package.metadata.embassy_docs] 36[package.metadata.embassy_docs]
37src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" 37src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/"
38src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" 38src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/"
39features = ["defmt"] 39features = ["defmt", "scheduler-deadline"]
40flavors = [ 40flavors = [
41 { name = "std", target = "x86_64-unknown-linux-gnu", features = ["arch-std", "executor-thread"] }, 41 { name = "std", target = "x86_64-unknown-linux-gnu", features = ["arch-std", "executor-thread"] },
42 { name = "wasm", target = "wasm32-unknown-unknown", features = ["arch-wasm", "executor-thread"] }, 42 { name = "wasm", target = "wasm32-unknown-unknown", features = ["arch-wasm", "executor-thread"] },
diff --git a/embassy-executor/src/metadata.rs b/embassy-executor/src/metadata.rs
index 81c5afafb..4220048a6 100644
--- a/embassy-executor/src/metadata.rs
+++ b/embassy-executor/src/metadata.rs
@@ -63,8 +63,8 @@ impl Metadata {
63 63
64 /// Get this task's deadline. 64 /// Get this task's deadline.
65 #[cfg(feature = "scheduler-deadline")] 65 #[cfg(feature = "scheduler-deadline")]
66 pub fn deadline(&self) -> &raw::Deadline { 66 pub fn deadline(&self) -> u64 {
67 &self.deadline 67 self.deadline.instant_ticks()
68 } 68 }
69 69
70 /// Set this task's deadline. 70 /// Set this task's deadline.
@@ -79,7 +79,7 @@ impl Metadata {
79 /// This brings it back to the defaul where it's not scheduled ahead of other tasks. 79 /// This brings it back to the defaul where it's not scheduled ahead of other tasks.
80 #[cfg(feature = "scheduler-deadline")] 80 #[cfg(feature = "scheduler-deadline")]
81 pub fn unset_deadline(&self) { 81 pub fn unset_deadline(&self) {
82 self.deadline.set(Deadline::UNSET_DEADLINE_TICKS); 82 self.deadline.set(Deadline::UNSET_TICKS);
83 } 83 }
84 84
85 /// Set this task's deadline `duration_ticks` in the future from when 85 /// Set this task's deadline `duration_ticks` in the future from when
@@ -110,7 +110,7 @@ impl Metadata {
110 /// Returns the deadline that was set. 110 /// Returns the deadline that was set.
111 #[cfg(feature = "scheduler-deadline")] 111 #[cfg(feature = "scheduler-deadline")]
112 pub fn increment_deadline(&self, duration_ticks: u64) { 112 pub fn increment_deadline(&self, duration_ticks: u64) {
113 let last = self.deadline().instant_ticks(); 113 let last = self.deadline();
114 114
115 // Since ticks is a u64, saturating add is PROBABLY overly cautious, leave 115 // Since ticks is a u64, saturating add is PROBABLY overly cautious, leave
116 // it for now, we can probably make this wrapping_add for performance 116 // it for now, we can probably make this wrapping_add for performance
diff --git a/embassy-executor/src/raw/deadline.rs b/embassy-executor/src/raw/deadline.rs
index f6d016ae7..cc89fadb0 100644
--- a/embassy-executor/src/raw/deadline.rs
+++ b/embassy-executor/src/raw/deadline.rs
@@ -7,7 +7,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
7/// Note: Interacting with the deadline should be done locally in a task. 7/// Note: Interacting with the deadline should be done locally in a task.
8/// In theory you could try to set or read the deadline from another task, 8/// In theory you could try to set or read the deadline from another task,
9/// but that will result in weird (though not unsound) behavior. 9/// but that will result in weird (though not unsound) behavior.
10pub struct Deadline { 10pub(crate) struct Deadline {
11 instant_ticks_hi: AtomicU32, 11 instant_ticks_hi: AtomicU32,
12 instant_ticks_lo: AtomicU32, 12 instant_ticks_lo: AtomicU32,
13} 13}
@@ -21,7 +21,7 @@ impl Deadline {
21 } 21 }
22 22
23 pub(crate) const fn new_unset() -> Self { 23 pub(crate) const fn new_unset() -> Self {
24 Self::new(Self::UNSET_DEADLINE_TICKS) 24 Self::new(Self::UNSET_TICKS)
25 } 25 }
26 26
27 pub(crate) fn set(&self, instant_ticks: u64) { 27 pub(crate) fn set(&self, instant_ticks: u64) {
@@ -31,7 +31,7 @@ impl Deadline {
31 } 31 }
32 32
33 /// Deadline value in ticks, same time base and ticks as `embassy-time` 33 /// Deadline value in ticks, same time base and ticks as `embassy-time`
34 pub fn instant_ticks(&self) -> u64 { 34 pub(crate) fn instant_ticks(&self) -> u64 {
35 let hi = self.instant_ticks_hi.load(Ordering::Relaxed) as u64; 35 let hi = self.instant_ticks_hi.load(Ordering::Relaxed) as u64;
36 let lo = self.instant_ticks_lo.load(Ordering::Relaxed) as u64; 36 let lo = self.instant_ticks_lo.load(Ordering::Relaxed) as u64;
37 37
@@ -40,11 +40,5 @@ impl Deadline {
40 40
41 /// Sentinel value representing an "unset" deadline, which has lower priority 41 /// Sentinel value representing an "unset" deadline, which has lower priority
42 /// than any other set deadline value 42 /// than any other set deadline value
43 pub const UNSET_DEADLINE_TICKS: u64 = u64::MAX; 43 pub(crate) const UNSET_TICKS: u64 = u64::MAX;
44
45 /// Does the given Deadline represent an "unset" deadline?
46 #[inline]
47 pub fn is_unset(&self) -> bool {
48 self.instant_ticks() == Self::UNSET_DEADLINE_TICKS
49 }
50} 44}
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 6a9dd9749..51a363385 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -40,7 +40,7 @@ use core::sync::atomic::Ordering;
40use core::task::{Context, Poll, Waker}; 40use core::task::{Context, Poll, Waker};
41 41
42#[cfg(feature = "scheduler-deadline")] 42#[cfg(feature = "scheduler-deadline")]
43pub use deadline::Deadline; 43pub(crate) use deadline::Deadline;
44use embassy_executor_timer_queue::TimerQueueItem; 44use embassy_executor_timer_queue::TimerQueueItem;
45#[cfg(feature = "arch-avr")] 45#[cfg(feature = "arch-avr")]
46use portable_atomic::AtomicPtr; 46use portable_atomic::AtomicPtr;
@@ -303,11 +303,7 @@ impl<F: Future + 'static> AvailableTask<F> {
303 // By default, deadlines are set to the maximum value, so that any task WITH 303 // By default, deadlines are set to the maximum value, so that any task WITH
304 // a set deadline will ALWAYS be scheduled BEFORE a task WITHOUT a set deadline 304 // a set deadline will ALWAYS be scheduled BEFORE a task WITHOUT a set deadline
305 #[cfg(feature = "scheduler-deadline")] 305 #[cfg(feature = "scheduler-deadline")]
306 self.task 306 self.task.raw.metadata.unset_deadline();
307 .raw
308 .metadata
309 .deadline()
310 .set(deadline::Deadline::UNSET_DEADLINE_TICKS);
311 307
312 let task = TaskRef::new(self.task); 308 let task = TaskRef::new(self.task);
313 309
diff --git a/embassy-executor/src/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs
index 29c977226..d98c26f73 100644
--- a/embassy-executor/src/raw/run_queue.rs
+++ b/embassy-executor/src/raw/run_queue.rs
@@ -108,12 +108,8 @@ impl RunQueue {
108 /// runqueue are both empty, at which point this function will return. 108 /// runqueue are both empty, at which point this function will return.
109 #[cfg(feature = "scheduler-deadline")] 109 #[cfg(feature = "scheduler-deadline")]
110 pub(crate) fn dequeue_all(&self, on_task: impl Fn(TaskRef)) { 110 pub(crate) fn dequeue_all(&self, on_task: impl Fn(TaskRef)) {
111 let mut sorted = SortedList::<TaskHeader>::new_with_cmp(|lhs, rhs| { 111 let mut sorted =
112 lhs.metadata 112 SortedList::<TaskHeader>::new_with_cmp(|lhs, rhs| lhs.metadata.deadline().cmp(&rhs.metadata.deadline()));
113 .deadline()
114 .instant_ticks()
115 .cmp(&rhs.metadata.deadline().instant_ticks())
116 });
117 113
118 loop { 114 loop {
119 // For each loop, grab any newly pended items 115 // For each loop, grab any newly pended items