diff options
Diffstat (limited to 'embassy-executor/src/raw/mod.rs')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index f6c66da5a..bd0cff26b 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -22,7 +22,6 @@ use core::ptr::NonNull; | |||
| 22 | use core::task::{Context, Poll}; | 22 | use core::task::{Context, Poll}; |
| 23 | 23 | ||
| 24 | use atomic_polyfill::{AtomicU32, Ordering}; | 24 | use atomic_polyfill::{AtomicU32, Ordering}; |
| 25 | use critical_section::CriticalSection; | ||
| 26 | #[cfg(feature = "integrated-timers")] | 25 | #[cfg(feature = "integrated-timers")] |
| 27 | use embassy_time::driver::{self, AlarmHandle}; | 26 | use embassy_time::driver::{self, AlarmHandle}; |
| 28 | #[cfg(feature = "integrated-timers")] | 27 | #[cfg(feature = "integrated-timers")] |
| @@ -373,11 +372,11 @@ impl SyncExecutor { | |||
| 373 | /// - `task` must be set up to run in this executor. | 372 | /// - `task` must be set up to run in this executor. |
| 374 | /// - `task` must NOT be already enqueued (in this executor or another one). | 373 | /// - `task` must NOT be already enqueued (in this executor or another one). |
| 375 | #[inline(always)] | 374 | #[inline(always)] |
| 376 | unsafe fn enqueue(&self, cs: CriticalSection, task: TaskRef) { | 375 | unsafe fn enqueue(&self, task: TaskRef) { |
| 377 | #[cfg(feature = "rtos-trace")] | 376 | #[cfg(feature = "rtos-trace")] |
| 378 | trace::task_ready_begin(task.as_ptr() as u32); | 377 | trace::task_ready_begin(task.as_ptr() as u32); |
| 379 | 378 | ||
| 380 | if self.run_queue.enqueue(cs, task) { | 379 | if self.run_queue.enqueue(task) { |
| 381 | self.pender.pend(); | 380 | self.pender.pend(); |
| 382 | } | 381 | } |
| 383 | } | 382 | } |
| @@ -394,9 +393,7 @@ impl SyncExecutor { | |||
| 394 | #[cfg(feature = "rtos-trace")] | 393 | #[cfg(feature = "rtos-trace")] |
| 395 | trace::task_new(task.as_ptr() as u32); | 394 | trace::task_new(task.as_ptr() as u32); |
| 396 | 395 | ||
| 397 | critical_section::with(|cs| { | 396 | self.enqueue(task); |
| 398 | self.enqueue(cs, task); | ||
| 399 | }) | ||
| 400 | } | 397 | } |
| 401 | 398 | ||
| 402 | /// # Safety | 399 | /// # Safety |
| @@ -552,24 +549,25 @@ impl Executor { | |||
| 552 | /// | 549 | /// |
| 553 | /// You can obtain a `TaskRef` from a `Waker` using [`task_from_waker`]. | 550 | /// You can obtain a `TaskRef` from a `Waker` using [`task_from_waker`]. |
| 554 | pub fn wake_task(task: TaskRef) { | 551 | pub fn wake_task(task: TaskRef) { |
| 555 | critical_section::with(|cs| { | 552 | let header = task.header(); |
| 556 | let header = task.header(); | ||
| 557 | let state = header.state.load(Ordering::Relaxed); | ||
| 558 | 553 | ||
| 554 | let res = header.state.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| { | ||
| 559 | // If already scheduled, or if not started, | 555 | // If already scheduled, or if not started, |
| 560 | if (state & STATE_RUN_QUEUED != 0) || (state & STATE_SPAWNED == 0) { | 556 | if (state & STATE_RUN_QUEUED != 0) || (state & STATE_SPAWNED == 0) { |
| 561 | return; | 557 | None |
| 558 | } else { | ||
| 559 | // Mark it as scheduled | ||
| 560 | Some(state | STATE_RUN_QUEUED) | ||
| 562 | } | 561 | } |
| 562 | }); | ||
| 563 | 563 | ||
| 564 | // Mark it as scheduled | 564 | if res.is_ok() { |
| 565 | header.state.store(state | STATE_RUN_QUEUED, Ordering::Relaxed); | ||
| 566 | |||
| 567 | // We have just marked the task as scheduled, so enqueue it. | 565 | // We have just marked the task as scheduled, so enqueue it. |
| 568 | unsafe { | 566 | unsafe { |
| 569 | let executor = header.executor.get().unwrap_unchecked(); | 567 | let executor = header.executor.get().unwrap_unchecked(); |
| 570 | executor.enqueue(cs, task); | 568 | executor.enqueue(task); |
| 571 | } | 569 | } |
| 572 | }) | 570 | } |
| 573 | } | 571 | } |
| 574 | 572 | ||
| 575 | #[cfg(feature = "integrated-timers")] | 573 | #[cfg(feature = "integrated-timers")] |
