aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor/src/raw/mod.rs')
-rw-r--r--embassy-executor/src/raw/mod.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index f9c6509f1..14d689900 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -50,7 +50,7 @@ pub(crate) struct TaskHeader {
50} 50}
51 51
52/// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. 52/// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased.
53#[derive(Clone, Copy)] 53#[derive(Clone, Copy, PartialEq)]
54pub struct TaskRef { 54pub struct TaskRef {
55 ptr: NonNull<TaskHeader>, 55 ptr: NonNull<TaskHeader>,
56} 56}
@@ -72,6 +72,16 @@ impl TaskRef {
72 } 72 }
73 } 73 }
74 74
75 /// # Safety
76 ///
77 /// The result of this function must only be compared
78 /// for equality, or stored, but not used.
79 pub const unsafe fn dangling() -> Self {
80 Self {
81 ptr: NonNull::dangling(),
82 }
83 }
84
75 pub(crate) fn header(self) -> &'static TaskHeader { 85 pub(crate) fn header(self) -> &'static TaskHeader {
76 unsafe { self.ptr.as_ref() } 86 unsafe { self.ptr.as_ref() }
77 } 87 }
@@ -88,6 +98,30 @@ impl TaskRef {
88 &self.header().timer_queue_item 98 &self.header().timer_queue_item
89 } 99 }
90 100
101 /// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
102 ///
103 /// Entering this state prevents the task from being respawned while in a timer queue.
104 ///
105 /// Safety:
106 ///
107 /// This functions should only be called by the timer queue implementation, before
108 /// enqueueing the timer item.
109 #[cfg(feature = "integrated-timers")]
110 pub unsafe fn timer_enqueue(&self) -> timer_queue::TimerEnqueueOperation {
111 self.header().state.timer_enqueue()
112 }
113
114 /// Unmark the task as timer-queued.
115 ///
116 /// Safety:
117 ///
118 /// This functions should only be called by the timer queue implementation, after the task has
119 /// been removed from the timer queue.
120 #[cfg(feature = "integrated-timers")]
121 pub unsafe fn timer_dequeue(&self) {
122 self.header().state.timer_dequeue()
123 }
124
91 /// The returned pointer is valid for the entire TaskStorage. 125 /// The returned pointer is valid for the entire TaskStorage.
92 pub(crate) fn as_ptr(self) -> *const TaskHeader { 126 pub(crate) fn as_ptr(self) -> *const TaskHeader {
93 self.ptr.as_ptr() 127 self.ptr.as_ptr()