aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/state_atomics.rs18
-rw-r--r--embassy-executor/src/raw/state_atomics_arm.rs19
-rw-r--r--embassy-executor/src/raw/state_critical_section.rs21
-rw-r--r--embassy-executor/src/raw/timer_queue.rs4
4 files changed, 4 insertions, 58 deletions
diff --git a/embassy-executor/src/raw/state_atomics.rs b/embassy-executor/src/raw/state_atomics.rs
index e1279ac0b..e4127897e 100644
--- a/embassy-executor/src/raw/state_atomics.rs
+++ b/embassy-executor/src/raw/state_atomics.rs
@@ -4,9 +4,6 @@ use core::sync::atomic::{AtomicU32, Ordering};
4pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 4pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
5/// Task is in the executor run queue 5/// Task is in the executor run queue
6pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 6pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
7/// Task is in the executor timer queue
8#[cfg(feature = "integrated-timers")]
9pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
10 7
11pub(crate) struct State { 8pub(crate) struct State {
12 state: AtomicU32, 9 state: AtomicU32,
@@ -55,19 +52,4 @@ impl State {
55 let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel); 52 let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel);
56 state & STATE_SPAWNED != 0 53 state & STATE_SPAWNED != 0
57 } 54 }
58
59 /// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
60 #[cfg(feature = "integrated-timers")]
61 #[inline(always)]
62 pub fn timer_enqueue(&self) -> bool {
63 let old_state = self.state.fetch_or(STATE_TIMER_QUEUED, Ordering::AcqRel);
64 old_state & STATE_TIMER_QUEUED == 0
65 }
66
67 /// Unmark the task as timer-queued.
68 #[cfg(feature = "integrated-timers")]
69 #[inline(always)]
70 pub fn timer_dequeue(&self) {
71 self.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::AcqRel);
72 }
73} 55}
diff --git a/embassy-executor/src/raw/state_atomics_arm.rs b/embassy-executor/src/raw/state_atomics_arm.rs
index e4dfe5093..b673c7359 100644
--- a/embassy-executor/src/raw/state_atomics_arm.rs
+++ b/embassy-executor/src/raw/state_atomics_arm.rs
@@ -11,9 +11,8 @@ pub(crate) struct State {
11 spawned: AtomicBool, 11 spawned: AtomicBool,
12 /// Task is in the executor run queue 12 /// Task is in the executor run queue
13 run_queued: AtomicBool, 13 run_queued: AtomicBool,
14 /// Task is in the executor timer queue
15 timer_queued: AtomicBool,
16 pad: AtomicBool, 14 pad: AtomicBool,
15 pad2: AtomicBool,
17} 16}
18 17
19impl State { 18impl State {
@@ -21,8 +20,8 @@ impl State {
21 Self { 20 Self {
22 spawned: AtomicBool::new(false), 21 spawned: AtomicBool::new(false),
23 run_queued: AtomicBool::new(false), 22 run_queued: AtomicBool::new(false),
24 timer_queued: AtomicBool::new(false),
25 pad: AtomicBool::new(false), 23 pad: AtomicBool::new(false),
24 pad2: AtomicBool::new(false),
26 } 25 }
27 } 26 }
28 27
@@ -86,18 +85,4 @@ impl State {
86 self.run_queued.store(false, Ordering::Relaxed); 85 self.run_queued.store(false, Ordering::Relaxed);
87 r 86 r
88 } 87 }
89
90 /// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
91 #[cfg(feature = "integrated-timers")]
92 #[inline(always)]
93 pub fn timer_enqueue(&self) -> bool {
94 !self.timer_queued.swap(true, Ordering::Relaxed)
95 }
96
97 /// Unmark the task as timer-queued.
98 #[cfg(feature = "integrated-timers")]
99 #[inline(always)]
100 pub fn timer_dequeue(&self) {
101 self.timer_queued.store(false, Ordering::Relaxed);
102 }
103} 88}
diff --git a/embassy-executor/src/raw/state_critical_section.rs b/embassy-executor/src/raw/state_critical_section.rs
index c3cc1b0b7..b92eed006 100644
--- a/embassy-executor/src/raw/state_critical_section.rs
+++ b/embassy-executor/src/raw/state_critical_section.rs
@@ -6,9 +6,6 @@ use critical_section::Mutex;
6pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 6pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
7/// Task is in the executor run queue 7/// Task is in the executor run queue
8pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 8pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
9/// Task is in the executor timer queue
10#[cfg(feature = "integrated-timers")]
11pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
12 9
13pub(crate) struct State { 10pub(crate) struct State {
14 state: Mutex<Cell<u32>>, 11 state: Mutex<Cell<u32>>,
@@ -72,22 +69,4 @@ impl State {
72 ok 69 ok
73 }) 70 })
74 } 71 }
75
76 /// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
77 #[cfg(feature = "integrated-timers")]
78 #[inline(always)]
79 pub fn timer_enqueue(&self) -> bool {
80 self.update(|s| {
81 let ok = *s & STATE_TIMER_QUEUED == 0;
82 *s |= STATE_TIMER_QUEUED;
83 ok
84 })
85 }
86
87 /// Unmark the task as timer-queued.
88 #[cfg(feature = "integrated-timers")]
89 #[inline(always)]
90 pub fn timer_dequeue(&self) {
91 self.update(|s| *s &= !STATE_TIMER_QUEUED);
92 }
93} 72}
diff --git a/embassy-executor/src/raw/timer_queue.rs b/embassy-executor/src/raw/timer_queue.rs
index 953bf014f..513397090 100644
--- a/embassy-executor/src/raw/timer_queue.rs
+++ b/embassy-executor/src/raw/timer_queue.rs
@@ -39,7 +39,7 @@ impl TimerQueue {
39 unsafe { 39 unsafe {
40 let task = p.header(); 40 let task = p.header();
41 let item = &task.timer_queue_item; 41 let item = &task.timer_queue_item;
42 if task.state.timer_enqueue() { 42 if item.next.get().is_none() {
43 // If not in the queue, add it and update. 43 // If not in the queue, add it and update.
44 let prev = self.head.replace(Some(p)); 44 let prev = self.head.replace(Some(p));
45 item.next.set(prev); 45 item.next.set(prev);
@@ -93,7 +93,7 @@ impl TimerQueue {
93 } else { 93 } else {
94 // Remove it 94 // Remove it
95 prev.set(item.next.get()); 95 prev.set(item.next.get());
96 task.state.timer_dequeue(); 96 item.next.set(None);
97 } 97 }
98 } 98 }
99 } 99 }