aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/deadline.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor/src/raw/deadline.rs')
-rw-r--r--embassy-executor/src/raw/deadline.rs109
1 files changed, 0 insertions, 109 deletions
diff --git a/embassy-executor/src/raw/deadline.rs b/embassy-executor/src/raw/deadline.rs
index 5b585195d..d08dd06ed 100644
--- a/embassy-executor/src/raw/deadline.rs
+++ b/embassy-executor/src/raw/deadline.rs
@@ -1,6 +1,4 @@
1use core::future::{poll_fn, Future};
2use core::sync::atomic::{AtomicU32, Ordering}; 1use core::sync::atomic::{AtomicU32, Ordering};
3use core::task::Poll;
4 2
5/// A type for interacting with the deadline of the current task 3/// A type for interacting with the deadline of the current task
6/// 4///
@@ -49,111 +47,4 @@ impl Deadline {
49 pub fn is_unset(&self) -> bool { 47 pub fn is_unset(&self) -> bool {
50 self.instant_ticks() == Self::UNSET_DEADLINE_TICKS 48 self.instant_ticks() == Self::UNSET_DEADLINE_TICKS
51 } 49 }
52
53 /// Set the current task's deadline at exactly `instant_ticks`
54 ///
55 /// This method is a future in order to access the currently executing task's
56 /// header which contains the deadline.
57 ///
58 /// Analogous to `Timer::at`.
59 ///
60 /// This method does NOT check whether the deadline has already passed.
61 #[must_use = "Setting deadline must be polled to be effective"]
62 pub fn set_current_task_deadline(instant_ticks: u64) -> impl Future<Output = ()> {
63 poll_fn(move |cx| {
64 let task = super::task_from_waker(cx.waker());
65 task.header().metadata.deadline().set(instant_ticks);
66 Poll::Ready(())
67 })
68 }
69
70 /// Set the current task's deadline `duration_ticks` in the future from when
71 /// this future is polled. This deadline is saturated to the max tick value.
72 ///
73 /// This method is a future in order to access the currently executing task's
74 /// header which contains the deadline.
75 ///
76 /// Analogous to `Timer::after`.
77 ///
78 /// Returns the deadline that was set.
79 #[must_use = "Setting deadline must be polled to be effective"]
80 pub fn set_current_task_deadline_after(duration_ticks: u64) -> impl Future<Output = Deadline> {
81 poll_fn(move |cx| {
82 let task = super::task_from_waker(cx.waker());
83 let now = embassy_time_driver::now();
84
85 // Since ticks is a u64, saturating add is PROBABLY overly cautious, leave
86 // it for now, we can probably make this wrapping_add for performance
87 // reasons later.
88 let deadline = now.saturating_add(duration_ticks);
89
90 task.header().metadata.deadline().set(deadline);
91
92 Poll::Ready(Deadline::new(deadline))
93 })
94 }
95
96 /// Set the current task's deadline `increment_ticks` from the previous deadline.
97 ///
98 /// This deadline is saturated to the max tick value.
99 ///
100 /// Note that by default (unless otherwise set), tasks start life with the deadline
101 /// u64::MAX, which means this method will have no effect.
102 ///
103 /// This method is a future in order to access the currently executing task's
104 /// header which contains the deadline
105 ///
106 /// Analogous to one increment of `Ticker::every().next()`.
107 ///
108 /// Returns the deadline that was set.
109 #[must_use = "Setting deadline must be polled to be effective"]
110 pub fn increment_current_task_deadline(increment_ticks: u64) -> impl Future<Output = Deadline> {
111 poll_fn(move |cx| {
112 let task_header = super::task_from_waker(cx.waker()).header();
113
114 // Get the last value
115 let last = task_header.metadata.deadline().instant_ticks();
116
117 // Since ticks is a u64, saturating add is PROBABLY overly cautious, leave
118 // it for now, we can probably make this wrapping_add for performance
119 // reasons later.
120 let deadline = last.saturating_add(increment_ticks);
121
122 // Store the new value
123 task_header.metadata.deadline().set(deadline);
124
125 Poll::Ready(Deadline::new(deadline))
126 })
127 }
128
129 /// Get the current task's deadline as a tick value.
130 ///
131 /// This method is a future in order to access the currently executing task's
132 /// header which contains the deadline
133 pub fn get_current_task_deadline() -> impl Future<Output = Self> {
134 poll_fn(move |cx| {
135 let task = super::task_from_waker(cx.waker());
136
137 let deadline = task.header().metadata.deadline().instant_ticks();
138 Poll::Ready(Self::new(deadline))
139 })
140 }
141
142 /// Clear the current task's deadline, returning the previous value.
143 ///
144 /// This sets the deadline to the default value of `u64::MAX`, meaning all
145 /// tasks with set deadlines will be scheduled BEFORE this task.
146 #[must_use = "Clearing deadline must be polled to be effective"]
147 pub fn clear_current_task_deadline() -> impl Future<Output = Self> {
148 poll_fn(move |cx| {
149 let task_header = super::task_from_waker(cx.waker()).header();
150
151 // get the old value
152 let deadline = task_header.metadata.deadline().instant_ticks();
153 // Store the default value
154 task_header.metadata.deadline().set(Self::UNSET_DEADLINE_TICKS);
155
156 Poll::Ready(Self::new(deadline))
157 })
158 }
159} 50}