diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-04-11 07:36:23 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-04-11 07:36:23 +0200 |
| commit | d8c92c53d647b170cb49ede1b608e58c2dd676d2 (patch) | |
| tree | d4fb6ee79087b598cad5d5fe5ce023626d4a21be /embassy-executor | |
| parent | 05b2b2fb5f0f8d52689057c22dd2fa026d6cc796 (diff) | |
| parent | 1f25d2ba8335300368b32f9ceedf163376dfdb6f (diff) | |
Merge remote-tracking branch 'upstream/master' into u32-partition
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/Cargo.toml | 19 | ||||
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 28 | ||||
| -rw-r--r-- | embassy-executor/src/raw/run_queue.rs | 18 |
3 files changed, 33 insertions, 32 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index bb8a46c82..29e1bd478 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -14,21 +14,18 @@ categories = [ | |||
| 14 | [package.metadata.embassy_docs] | 14 | [package.metadata.embassy_docs] |
| 15 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" | 15 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" |
| 16 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" | 16 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" |
| 17 | features = ["nightly", "defmt"] | 17 | features = ["nightly", "defmt", "pender-callback"] |
| 18 | flavors = [ | 18 | flavors = [ |
| 19 | { name = "std", target = "x86_64-unknown-linux-gnu", features = ["std"] }, | 19 | { name = "std", target = "x86_64-unknown-linux-gnu", features = ["arch-std", "executor-thread"] }, |
| 20 | { name = "wasm", target = "wasm32-unknown-unknown", features = ["wasm"] }, | 20 | { name = "wasm", target = "wasm32-unknown-unknown", features = ["arch-wasm", "executor-thread"] }, |
| 21 | { name = "thumbv6m-none-eabi", target = "thumbv6m-none-eabi", features = [] }, | 21 | { name = "cortex-m", target = "thumbv7em-none-eabi", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }, |
| 22 | { name = "thumbv7m-none-eabi", target = "thumbv7m-none-eabi", features = [] }, | 22 | { name = "riscv32", target = "riscv32imac-unknown-none-elf", features = ["arch-riscv32", "executor-thread"] }, |
| 23 | { name = "thumbv7em-none-eabi", target = "thumbv7em-none-eabi", features = [] }, | ||
| 24 | { name = "thumbv7em-none-eabihf", target = "thumbv7em-none-eabihf", features = [] }, | ||
| 25 | { name = "thumbv8m.base-none-eabi", target = "thumbv8m.base-none-eabi", features = [] }, | ||
| 26 | { name = "thumbv8m.main-none-eabi", target = "thumbv8m.main-none-eabi", features = [] }, | ||
| 27 | { name = "thumbv8m.main-none-eabihf", target = "thumbv8m.main-none-eabihf", features = [] }, | ||
| 28 | ] | 23 | ] |
| 29 | 24 | ||
| 30 | [package.metadata.docs.rs] | 25 | [package.metadata.docs.rs] |
| 31 | features = ["std", "nightly", "defmt"] | 26 | default-target = "thumbv7em-none-eabi" |
| 27 | targets = ["thumbv7em-none-eabi"] | ||
| 28 | features = ["nightly", "defmt", "pender-callback", "arch-cortex-m", "executor-thread", "executor-interrupt"] | ||
| 32 | 29 | ||
| 33 | [features] | 30 | [features] |
| 34 | 31 | ||
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")] |
diff --git a/embassy-executor/src/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs index 362157535..a88174a0c 100644 --- a/embassy-executor/src/raw/run_queue.rs +++ b/embassy-executor/src/raw/run_queue.rs | |||
| @@ -2,7 +2,6 @@ use core::ptr; | |||
| 2 | use core::ptr::NonNull; | 2 | use core::ptr::NonNull; |
| 3 | 3 | ||
| 4 | use atomic_polyfill::{AtomicPtr, Ordering}; | 4 | use atomic_polyfill::{AtomicPtr, Ordering}; |
| 5 | use critical_section::CriticalSection; | ||
| 6 | 5 | ||
| 7 | use super::{TaskHeader, TaskRef}; | 6 | use super::{TaskHeader, TaskRef}; |
| 8 | 7 | ||
| @@ -46,11 +45,18 @@ impl RunQueue { | |||
| 46 | /// | 45 | /// |
| 47 | /// `item` must NOT be already enqueued in any queue. | 46 | /// `item` must NOT be already enqueued in any queue. |
| 48 | #[inline(always)] | 47 | #[inline(always)] |
| 49 | pub(crate) unsafe fn enqueue(&self, _cs: CriticalSection, task: TaskRef) -> bool { | 48 | pub(crate) unsafe fn enqueue(&self, task: TaskRef) -> bool { |
| 50 | let prev = self.head.load(Ordering::Relaxed); | 49 | let mut was_empty = false; |
| 51 | task.header().run_queue_item.next.store(prev, Ordering::Relaxed); | 50 | |
| 52 | self.head.store(task.as_ptr() as _, Ordering::Relaxed); | 51 | self.head |
| 53 | prev.is_null() | 52 | .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |prev| { |
| 53 | was_empty = prev.is_null(); | ||
| 54 | task.header().run_queue_item.next.store(prev, Ordering::Relaxed); | ||
| 55 | Some(task.as_ptr() as *mut _) | ||
| 56 | }) | ||
| 57 | .ok(); | ||
| 58 | |||
| 59 | was_empty | ||
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | /// Empty the queue, then call `on_task` for each task that was in the queue. | 62 | /// Empty the queue, then call `on_task` for each task that was in the queue. |
