diff options
| author | Grant Miller <[email protected]> | 2023-01-31 21:42:45 -0600 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2023-01-31 21:46:25 -0600 |
| commit | 791fbb3ca0caf81882f67caea9e71adf43496261 (patch) | |
| tree | 6e55449b04fe6ac7195bdb203969cc0c59b90ab6 | |
| parent | 4a8e9cf4d9f682bfe4942559da7e76315216c377 (diff) | |
Make `poll_fn` lazily initialized again
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index e93e60362..42bd82262 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -47,7 +47,7 @@ pub(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<Option<&'static Executor>>, | 49 | pub(crate) executor: Cell<Option<&'static Executor>>, |
| 50 | poll_fn: unsafe fn(TaskRef), | 50 | poll_fn: Cell<Option<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>, |
| @@ -116,7 +116,8 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 116 | state: AtomicU32::new(0), | 116 | state: AtomicU32::new(0), |
| 117 | run_queue_item: RunQueueItem::new(), | 117 | run_queue_item: RunQueueItem::new(), |
| 118 | executor: Cell::new(None), | 118 | executor: Cell::new(None), |
| 119 | poll_fn: Self::poll, | 119 | // Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss` |
| 120 | poll_fn: Cell::new(None), | ||
| 120 | 121 | ||
| 121 | #[cfg(feature = "integrated-timers")] | 122 | #[cfg(feature = "integrated-timers")] |
| 122 | expires_at: Cell::new(Instant::from_ticks(0)), | 123 | expires_at: Cell::new(Instant::from_ticks(0)), |
| @@ -188,6 +189,7 @@ impl<F: Future + 'static> AvailableTask<F> { | |||
| 188 | 189 | ||
| 189 | fn initialize(self, future: impl FnOnce() -> F) -> TaskRef { | 190 | fn initialize(self, future: impl FnOnce() -> F) -> TaskRef { |
| 190 | unsafe { | 191 | unsafe { |
| 192 | self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll)); | ||
| 191 | self.task.future.write(future()); | 193 | self.task.future.write(future()); |
| 192 | } | 194 | } |
| 193 | TaskRef::new(self.task) | 195 | TaskRef::new(self.task) |
| @@ -410,7 +412,7 @@ impl Executor { | |||
| 410 | trace::task_exec_begin(p.as_ptr() as u32); | 412 | trace::task_exec_begin(p.as_ptr() as u32); |
| 411 | 413 | ||
| 412 | // Run the task | 414 | // Run the task |
| 413 | (task.poll_fn)(p); | 415 | task.poll_fn.get().unwrap_unchecked()(p); |
| 414 | 416 | ||
| 415 | #[cfg(feature = "rtos-trace")] | 417 | #[cfg(feature = "rtos-trace")] |
| 416 | trace::task_exec_end(); | 418 | trace::task_exec_end(); |
