aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/mod.rs
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2023-01-31 17:29:34 -0600
committerGrant Miller <[email protected]>2023-01-31 18:59:03 -0600
commita697f1517a9c54ba042bbf70e0b2ed762d300471 (patch)
tree93670390eb904f8c5fb00417f1da203333224dc2 /embassy-executor/src/raw/mod.rs
parent465e4c8b1940762cee6c75912a5289b70d34deca (diff)
Set `poll_fn` in `TaskStorage::new`
Diffstat (limited to 'embassy-executor/src/raw/mod.rs')
-rw-r--r--embassy-executor/src/raw/mod.rs35
1 files changed, 14 insertions, 21 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 183c5e6a2..8cdce92ec 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -46,8 +46,8 @@ pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
46pub(crate) struct TaskHeader { 46pub(crate) struct TaskHeader {
47 pub(crate) state: AtomicU32, 47 pub(crate) state: AtomicU32,
48 pub(crate) run_queue_item: RunQueueItem, 48 pub(crate) run_queue_item: RunQueueItem,
49 pub(crate) executor: Cell<*const Executor>, // Valid if state != 0 49 pub(crate) executor: Cell<*const Executor>, // Valid if state != 0
50 pub(crate) poll_fn: UninitCell<unsafe fn(TaskRef)>, // Valid if STATE_SPAWNED 50 poll_fn: unsafe fn(TaskRef),
51 51
52 #[cfg(feature = "integrated-timers")] 52 #[cfg(feature = "integrated-timers")]
53 pub(crate) expires_at: Cell<Instant>, 53 pub(crate) expires_at: Cell<Instant>,
@@ -55,22 +55,6 @@ pub(crate) struct TaskHeader {
55 pub(crate) timer_queue_item: timer_queue::TimerQueueItem, 55 pub(crate) timer_queue_item: timer_queue::TimerQueueItem,
56} 56}
57 57
58impl TaskHeader {
59 const fn new() -> Self {
60 Self {
61 state: AtomicU32::new(0),
62 run_queue_item: RunQueueItem::new(),
63 executor: Cell::new(ptr::null()),
64 poll_fn: UninitCell::uninit(),
65
66 #[cfg(feature = "integrated-timers")]
67 expires_at: Cell::new(Instant::from_ticks(0)),
68 #[cfg(feature = "integrated-timers")]
69 timer_queue_item: timer_queue::TimerQueueItem::new(),
70 }
71 }
72}
73
74/// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. 58/// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased.
75#[derive(Clone, Copy)] 59#[derive(Clone, Copy)]
76pub struct TaskRef { 60pub struct TaskRef {
@@ -128,7 +112,17 @@ impl<F: Future + 'static> TaskStorage<F> {
128 /// Create a new TaskStorage, in not-spawned state. 112 /// Create a new TaskStorage, in not-spawned state.
129 pub const fn new() -> Self { 113 pub const fn new() -> Self {
130 Self { 114 Self {
131 raw: TaskHeader::new(), 115 raw: TaskHeader {
116 state: AtomicU32::new(0),
117 run_queue_item: RunQueueItem::new(),
118 executor: Cell::new(ptr::null()),
119 poll_fn: Self::poll,
120
121 #[cfg(feature = "integrated-timers")]
122 expires_at: Cell::new(Instant::from_ticks(0)),
123 #[cfg(feature = "integrated-timers")]
124 timer_queue_item: timer_queue::TimerQueueItem::new(),
125 },
132 future: UninitCell::uninit(), 126 future: UninitCell::uninit(),
133 } 127 }
134 } 128 }
@@ -164,7 +158,6 @@ impl<F: Future + 'static> TaskStorage<F> {
164 158
165 unsafe fn spawn_initialize(&'static self, future: impl FnOnce() -> F) -> TaskRef { 159 unsafe fn spawn_initialize(&'static self, future: impl FnOnce() -> F) -> TaskRef {
166 // Initialize the task 160 // Initialize the task
167 self.raw.poll_fn.write(Self::poll);
168 self.future.write(future()); 161 self.future.write(future());
169 TaskRef::new(self) 162 TaskRef::new(self)
170 } 163 }
@@ -405,7 +398,7 @@ impl Executor {
405 trace::task_exec_begin(p.as_ptr() as u32); 398 trace::task_exec_begin(p.as_ptr() as u32);
406 399
407 // Run the task 400 // Run the task
408 task.poll_fn.read()(p); 401 (task.poll_fn)(p);
409 402
410 #[cfg(feature = "rtos-trace")] 403 #[cfg(feature = "rtos-trace")]
411 trace::task_exec_end(); 404 trace::task_exec_end();