diff options
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/src/raw/state_critical_section.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs index ec08f2f58..b69a6ac66 100644 --- a/embassy-executor/src/raw/state_critical_section.rs +++ b/embassy-executor/src/raw/state_critical_section.rs | |||
| @@ -3,13 +3,18 @@ use core::cell::Cell; | |||
| 3 | pub(crate) use critical_section::{with as locked, CriticalSection as Token}; | 3 | pub(crate) use critical_section::{with as locked, CriticalSection as Token}; |
| 4 | use critical_section::{CriticalSection, Mutex}; | 4 | use critical_section::{CriticalSection, Mutex}; |
| 5 | 5 | ||
| 6 | #[cfg(target_arch = "avr")] | ||
| 7 | type StateBits = u8; | ||
| 8 | #[cfg(not(target_arch = "avr"))] | ||
| 9 | type StateBits = usize; | ||
| 10 | |||
| 6 | /// Task is spawned (has a future) | 11 | /// Task is spawned (has a future) |
| 7 | pub(crate) const STATE_SPAWNED: u8 = 1 << 0; | 12 | pub(crate) const STATE_SPAWNED: StateBits = 1 << 0; |
| 8 | /// Task is in the executor run queue | 13 | /// Task is in the executor run queue |
| 9 | pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1; | 14 | pub(crate) const STATE_RUN_QUEUED: StateBits = 1 << 1; |
| 10 | 15 | ||
| 11 | pub(crate) struct State { | 16 | pub(crate) struct State { |
| 12 | state: Mutex<Cell<u8>>, | 17 | state: Mutex<Cell<StateBits>>, |
| 13 | } | 18 | } |
| 14 | 19 | ||
| 15 | impl State { | 20 | impl State { |
| @@ -19,11 +24,11 @@ impl State { | |||
| 19 | } | 24 | } |
| 20 | } | 25 | } |
| 21 | 26 | ||
| 22 | fn update<R>(&self, f: impl FnOnce(&mut u8) -> R) -> R { | 27 | fn update<R>(&self, f: impl FnOnce(&mut StateBits) -> R) -> R { |
| 23 | critical_section::with(|cs| self.update_with_cs(cs, f)) | 28 | critical_section::with(|cs| self.update_with_cs(cs, f)) |
| 24 | } | 29 | } |
| 25 | 30 | ||
| 26 | fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut u8) -> R) -> R { | 31 | fn update_with_cs<R>(&self, cs: CriticalSection<'_>, f: impl FnOnce(&mut StateBits) -> R) -> R { |
| 27 | let s = self.state.borrow(cs); | 32 | let s = self.state.borrow(cs); |
| 28 | let mut val = s.get(); | 33 | let mut val = s.get(); |
| 29 | let r = f(&mut val); | 34 | let r = f(&mut val); |
