diff options
| author | loris <[email protected]> | 2023-08-05 21:04:51 +0200 |
|---|---|---|
| committer | loris <[email protected]> | 2023-08-05 21:04:51 +0200 |
| commit | 66faba2df76bf76bcfcca30d159c5a39b64819e8 (patch) | |
| tree | a35fade618cb3043fcf652df0cfb3b83383276a9 | |
| parent | 0d8a9b1e7a963fe1a1a3cf0e10c33314bba65e2d (diff) | |
add wake_task_no_pend for expired timer enqueue inside run_queue
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index f3760f589..25c2ab0da 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -409,7 +409,7 @@ impl SyncExecutor { | |||
| 409 | #[allow(clippy::never_loop)] | 409 | #[allow(clippy::never_loop)] |
| 410 | loop { | 410 | loop { |
| 411 | #[cfg(feature = "integrated-timers")] | 411 | #[cfg(feature = "integrated-timers")] |
| 412 | self.timer_queue.dequeue_expired(Instant::now(), |task| wake_task(task)); | 412 | self.timer_queue.dequeue_expired(Instant::now(), wake_task_no_pend); |
| 413 | 413 | ||
| 414 | self.run_queue.dequeue_all(|p| { | 414 | self.run_queue.dequeue_all(|p| { |
| 415 | let task = p.header(); | 415 | let task = p.header(); |
| @@ -573,6 +573,31 @@ pub fn wake_task(task: TaskRef) { | |||
| 573 | } | 573 | } |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | /// Wake a task by `TaskRef` without calling pend. | ||
| 577 | /// | ||
| 578 | /// You can obtain a `TaskRef` from a `Waker` using [`task_from_waker`]. | ||
| 579 | pub fn wake_task_no_pend(task: TaskRef) { | ||
| 580 | let header = task.header(); | ||
| 581 | |||
| 582 | let res = header.state.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| { | ||
| 583 | // If already scheduled, or if not started, | ||
| 584 | if (state & STATE_RUN_QUEUED != 0) || (state & STATE_SPAWNED == 0) { | ||
| 585 | None | ||
| 586 | } else { | ||
| 587 | // Mark it as scheduled | ||
| 588 | Some(state | STATE_RUN_QUEUED) | ||
| 589 | } | ||
| 590 | }); | ||
| 591 | |||
| 592 | if res.is_ok() { | ||
| 593 | // We have just marked the task as scheduled, so enqueue it. | ||
| 594 | unsafe { | ||
| 595 | let executor = header.executor.get().unwrap_unchecked(); | ||
| 596 | executor.run_queue.enqueue(task); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | } | ||
| 600 | |||
| 576 | #[cfg(feature = "integrated-timers")] | 601 | #[cfg(feature = "integrated-timers")] |
| 577 | struct TimerQueue; | 602 | struct TimerQueue; |
| 578 | 603 | ||
