aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-12-16 19:03:00 +0100
committerDániel Buga <[email protected]>2024-12-16 20:37:02 +0100
commitc90d048ecb611908f5696b4f57d689bdb254aee6 (patch)
tree9800ad14610b683b0d5048f89e84a3d835822171 /embassy-executor/src
parenta8617429e4c3177a3e7c31b20ee36a2dfe6b6430 (diff)
Remove TIMER_QUEUED
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/state_atomics.rs32
-rw-r--r--embassy-executor/src/raw/state_atomics_arm.rs36
-rw-r--r--embassy-executor/src/raw/state_critical_section.rs25
3 files changed, 2 insertions, 91 deletions
diff --git a/embassy-executor/src/raw/state_atomics.rs b/embassy-executor/src/raw/state_atomics.rs
index d7350464f..6f5266bda 100644
--- a/embassy-executor/src/raw/state_atomics.rs
+++ b/embassy-executor/src/raw/state_atomics.rs
@@ -1,7 +1,5 @@
1use core::sync::atomic::{AtomicU32, Ordering}; 1use core::sync::atomic::{AtomicU32, Ordering};
2 2
3use super::timer_queue::TimerEnqueueOperation;
4
5#[derive(Clone, Copy)] 3#[derive(Clone, Copy)]
6pub(crate) struct Token(()); 4pub(crate) struct Token(());
7 5
@@ -16,8 +14,6 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
16pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 14pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
17/// Task is in the executor run queue 15/// Task is in the executor run queue
18pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 16pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
19/// Task is in the executor timer queue
20pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
21 17
22pub(crate) struct State { 18pub(crate) struct State {
23 state: AtomicU32, 19 state: AtomicU32,
@@ -71,32 +67,4 @@ impl State {
71 let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel); 67 let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel);
72 state & STATE_SPAWNED != 0 68 state & STATE_SPAWNED != 0
73 } 69 }
74
75 /// Mark the task as timer-queued. Return whether it can be enqueued.
76 #[inline(always)]
77 pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
78 if self
79 .state
80 .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| {
81 // If not started, ignore it
82 if state & STATE_SPAWNED == 0 {
83 None
84 } else {
85 // Mark it as enqueued
86 Some(state | STATE_TIMER_QUEUED)
87 }
88 })
89 .is_ok()
90 {
91 TimerEnqueueOperation::Enqueue
92 } else {
93 TimerEnqueueOperation::Ignore
94 }
95 }
96
97 /// Unmark the task as timer-queued.
98 #[inline(always)]
99 pub fn timer_dequeue(&self) {
100 self.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::Relaxed);
101 }
102} 70}
diff --git a/embassy-executor/src/raw/state_atomics_arm.rs b/embassy-executor/src/raw/state_atomics_arm.rs
index c1e8f69ab..4896b33c5 100644
--- a/embassy-executor/src/raw/state_atomics_arm.rs
+++ b/embassy-executor/src/raw/state_atomics_arm.rs
@@ -1,8 +1,6 @@
1use core::arch::asm; 1use core::arch::asm;
2use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering}; 2use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering};
3 3
4use super::timer_queue::TimerEnqueueOperation;
5
6#[derive(Clone, Copy)] 4#[derive(Clone, Copy)]
7pub(crate) struct Token(()); 5pub(crate) struct Token(());
8 6
@@ -16,7 +14,6 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
16// Must be kept in sync with the layout of `State`! 14// Must be kept in sync with the layout of `State`!
17pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 15pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
18pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 8; 16pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 8;
19pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 16;
20 17
21#[repr(C, align(4))] 18#[repr(C, align(4))]
22pub(crate) struct State { 19pub(crate) struct State {
@@ -24,9 +21,8 @@ pub(crate) struct State {
24 spawned: AtomicBool, 21 spawned: AtomicBool,
25 /// Task is in the executor run queue 22 /// Task is in the executor run queue
26 run_queued: AtomicBool, 23 run_queued: AtomicBool,
27 /// Task is in the executor timer queue
28 timer_queued: AtomicBool,
29 pad: AtomicBool, 24 pad: AtomicBool,
25 pad2: AtomicBool,
30} 26}
31 27
32impl State { 28impl State {
@@ -34,8 +30,8 @@ impl State {
34 Self { 30 Self {
35 spawned: AtomicBool::new(false), 31 spawned: AtomicBool::new(false),
36 run_queued: AtomicBool::new(false), 32 run_queued: AtomicBool::new(false),
37 timer_queued: AtomicBool::new(false),
38 pad: AtomicBool::new(false), 33 pad: AtomicBool::new(false),
34 pad2: AtomicBool::new(false),
39 } 35 }
40 } 36 }
41 37
@@ -101,32 +97,4 @@ impl State {
101 self.run_queued.store(false, Ordering::Relaxed); 97 self.run_queued.store(false, Ordering::Relaxed);
102 r 98 r
103 } 99 }
104
105 /// Mark the task as timer-queued. Return whether it can be enqueued.
106 #[inline(always)]
107 pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
108 if self
109 .as_u32()
110 .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| {
111 // If not started, ignore it
112 if state & STATE_SPAWNED == 0 {
113 None
114 } else {
115 // Mark it as enqueued
116 Some(state | STATE_TIMER_QUEUED)
117 }
118 })
119 .is_ok()
120 {
121 TimerEnqueueOperation::Enqueue
122 } else {
123 TimerEnqueueOperation::Ignore
124 }
125 }
126
127 /// Unmark the task as timer-queued.
128 #[inline(always)]
129 pub fn timer_dequeue(&self) {
130 self.timer_queued.store(false, Ordering::Relaxed);
131 }
132} 100}
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs
index 8e570b33c..29b10f6e3 100644
--- a/embassy-executor/src/raw/state_critical_section.rs
+++ b/embassy-executor/src/raw/state_critical_section.rs
@@ -3,14 +3,10 @@ use core::cell::Cell;
3pub(crate) use critical_section::{with as locked, CriticalSection as Token}; 3pub(crate) use critical_section::{with as locked, CriticalSection as Token};
4use critical_section::{CriticalSection, Mutex}; 4use critical_section::{CriticalSection, Mutex};
5 5
6use super::timer_queue::TimerEnqueueOperation;
7
8/// Task is spawned (has a future) 6/// Task is spawned (has a future)
9pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 7pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
10/// Task is in the executor run queue 8/// Task is in the executor run queue
11pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 9pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
12/// Task is in the executor timer queue
13pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
14 10
15pub(crate) struct State { 11pub(crate) struct State {
16 state: Mutex<Cell<u32>>, 12 state: Mutex<Cell<u32>>,
@@ -81,25 +77,4 @@ impl State {
81 ok 77 ok
82 }) 78 })
83 } 79 }
84
85 /// Mark the task as timer-queued. Return whether it can be enqueued.
86 #[inline(always)]
87 pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
88 self.update(|s| {
89 // FIXME: we need to split SPAWNED into two phases, to prevent enqueueing a task that is
90 // just being spawned, because its executor pointer may still be changing.
91 if *s & STATE_SPAWNED == STATE_SPAWNED {
92 *s |= STATE_TIMER_QUEUED;
93 TimerEnqueueOperation::Enqueue
94 } else {
95 TimerEnqueueOperation::Ignore
96 }
97 })
98 }
99
100 /// Unmark the task as timer-queued.
101 #[inline(always)]
102 pub fn timer_dequeue(&self) {
103 self.update(|s| *s &= !STATE_TIMER_QUEUED);
104 }
105} 80}