diff options
Diffstat (limited to 'embassy-executor/src/raw/state_atomics.rs')
| -rw-r--r-- | embassy-executor/src/raw/state_atomics.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/embassy-executor/src/raw/state_atomics.rs b/embassy-executor/src/raw/state_atomics.rs index e813548ae..6675875be 100644 --- a/embassy-executor/src/raw/state_atomics.rs +++ b/embassy-executor/src/raw/state_atomics.rs | |||
| @@ -1,4 +1,15 @@ | |||
| 1 | use core::sync::atomic::{AtomicU8, Ordering}; | 1 | // Prefer pointer-width atomic operations, as narrower ones may be slower. |
| 2 | #[cfg(all(target_pointer_width = "32", target_has_atomic = "32"))] | ||
| 3 | type AtomicState = core::sync::atomic::AtomicU32; | ||
| 4 | #[cfg(not(all(target_pointer_width = "32", target_has_atomic = "32")))] | ||
| 5 | type AtomicState = core::sync::atomic::AtomicU8; | ||
| 6 | |||
| 7 | #[cfg(all(target_pointer_width = "32", target_has_atomic = "32"))] | ||
| 8 | type StateBits = u32; | ||
| 9 | #[cfg(not(all(target_pointer_width = "32", target_has_atomic = "32")))] | ||
| 10 | type StateBits = u8; | ||
| 11 | |||
| 12 | use core::sync::atomic::Ordering; | ||
| 2 | 13 | ||
| 3 | #[derive(Clone, Copy)] | 14 | #[derive(Clone, Copy)] |
| 4 | pub(crate) struct Token(()); | 15 | pub(crate) struct Token(()); |
| @@ -11,18 +22,18 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R { | |||
| 11 | } | 22 | } |
| 12 | 23 | ||
| 13 | /// Task is spawned (has a future) | 24 | /// Task is spawned (has a future) |
| 14 | pub(crate) const STATE_SPAWNED: u8 = 1 << 0; | 25 | pub(crate) const STATE_SPAWNED: StateBits = 1 << 0; |
| 15 | /// Task is in the executor run queue | 26 | /// Task is in the executor run queue |
| 16 | pub(crate) const STATE_RUN_QUEUED: u8 = 1 << 1; | 27 | pub(crate) const STATE_RUN_QUEUED: StateBits = 1 << 1; |
| 17 | 28 | ||
| 18 | pub(crate) struct State { | 29 | pub(crate) struct State { |
| 19 | state: AtomicU8, | 30 | state: AtomicState, |
| 20 | } | 31 | } |
| 21 | 32 | ||
| 22 | impl State { | 33 | impl State { |
| 23 | pub const fn new() -> State { | 34 | pub const fn new() -> State { |
| 24 | Self { | 35 | Self { |
| 25 | state: AtomicU8::new(0), | 36 | state: AtomicState::new(0), |
| 26 | } | 37 | } |
| 27 | } | 38 | } |
| 28 | 39 | ||
