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.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index c8f1f46c2..4b17d4982 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -16,7 +16,6 @@ mod run_queue;
16#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")] 16#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")]
17mod state; 17mod state;
18 18
19pub mod timer_queue;
20#[cfg(feature = "trace")] 19#[cfg(feature = "trace")]
21pub mod trace; 20pub mod trace;
22pub(crate) mod util; 21pub(crate) mod util;
@@ -31,8 +30,9 @@ use core::ptr::NonNull;
31#[cfg(not(feature = "arch-avr"))] 30#[cfg(not(feature = "arch-avr"))]
32use core::sync::atomic::AtomicPtr; 31use core::sync::atomic::AtomicPtr;
33use core::sync::atomic::Ordering; 32use core::sync::atomic::Ordering;
34use core::task::{Context, Poll}; 33use core::task::{Context, Poll, Waker};
35 34
35use embassy_executor_timer_queue::TimerQueueItem;
36#[cfg(feature = "arch-avr")] 36#[cfg(feature = "arch-avr")]
37use portable_atomic::AtomicPtr; 37use portable_atomic::AtomicPtr;
38 38
@@ -42,6 +42,11 @@ use self::util::{SyncUnsafeCell, UninitCell};
42pub use self::waker::task_from_waker; 42pub use self::waker::task_from_waker;
43use super::SpawnToken; 43use super::SpawnToken;
44 44
45#[no_mangle]
46extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem {
47 unsafe { task_from_waker(waker).timer_queue_item() }
48}
49
45/// Raw task header for use in task pointers. 50/// Raw task header for use in task pointers.
46/// 51///
47/// A task can be in one of the following states: 52/// A task can be in one of the following states:
@@ -88,7 +93,7 @@ pub(crate) struct TaskHeader {
88 poll_fn: SyncUnsafeCell<Option<unsafe fn(TaskRef)>>, 93 poll_fn: SyncUnsafeCell<Option<unsafe fn(TaskRef)>>,
89 94
90 /// Integrated timer queue storage. This field should not be accessed outside of the timer queue. 95 /// Integrated timer queue storage. This field should not be accessed outside of the timer queue.
91 pub(crate) timer_queue_item: timer_queue::TimerQueueItem, 96 pub(crate) timer_queue_item: TimerQueueItem,
92 #[cfg(feature = "trace")] 97 #[cfg(feature = "trace")]
93 pub(crate) name: Option<&'static str>, 98 pub(crate) name: Option<&'static str>,
94 #[cfg(feature = "trace")] 99 #[cfg(feature = "trace")]
@@ -120,16 +125,6 @@ impl TaskRef {
120 } 125 }
121 } 126 }
122 127
123 /// # Safety
124 ///
125 /// The result of this function must only be compared
126 /// for equality, or stored, but not used.
127 pub const unsafe fn dangling() -> Self {
128 Self {
129 ptr: NonNull::dangling(),
130 }
131 }
132
133 pub(crate) fn header(self) -> &'static TaskHeader { 128 pub(crate) fn header(self) -> &'static TaskHeader {
134 unsafe { self.ptr.as_ref() } 129 unsafe { self.ptr.as_ref() }
135 } 130 }
@@ -140,9 +135,13 @@ impl TaskRef {
140 executor.as_ref().map(|e| Executor::wrap(e)) 135 executor.as_ref().map(|e| Executor::wrap(e))
141 } 136 }
142 137
143 /// Returns a reference to the timer queue item. 138 /// Returns a mutable reference to the timer queue item.
144 pub fn timer_queue_item(&self) -> &'static timer_queue::TimerQueueItem { 139 ///
145 &self.header().timer_queue_item 140 /// Safety
141 ///
142 /// This function must only be called in the context of the integrated timer queue.
143 pub unsafe fn timer_queue_item(mut self) -> &'static mut TimerQueueItem {
144 unsafe { &mut self.ptr.as_mut().timer_queue_item }
146 } 145 }
147 146
148 /// The returned pointer is valid for the entire TaskStorage. 147 /// The returned pointer is valid for the entire TaskStorage.
@@ -189,7 +188,7 @@ impl<F: Future + 'static> TaskStorage<F> {
189 // Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss` 188 // Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss`
190 poll_fn: SyncUnsafeCell::new(None), 189 poll_fn: SyncUnsafeCell::new(None),
191 190
192 timer_queue_item: timer_queue::TimerQueueItem::new(), 191 timer_queue_item: TimerQueueItem::new(),
193 #[cfg(feature = "trace")] 192 #[cfg(feature = "trace")]
194 name: None, 193 name: None,
195 #[cfg(feature = "trace")] 194 #[cfg(feature = "trace")]