aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/state_atomics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor/src/raw/state_atomics.rs')
-rw-r--r--embassy-executor/src/raw/state_atomics.rs32
1 files changed, 0 insertions, 32 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}