Remove TIMER_QUEUED state

This commit is contained in:
Dániel Buga 2024-12-08 23:04:43 +01:00
parent 6cc8709ecc
commit 12f58fbcfd
No known key found for this signature in database
4 changed files with 4 additions and 58 deletions

View File

@ -4,9 +4,6 @@ use core::sync::atomic::{AtomicU32, Ordering};
pub(crate) const STATE_SPAWNED: u32 = 1 << 0; pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
/// Task is in the executor run queue /// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
/// Task is in the executor timer queue
#[cfg(feature = "integrated-timers")]
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
pub(crate) struct State { pub(crate) struct State {
state: AtomicU32, state: AtomicU32,
@ -55,19 +52,4 @@ impl State {
let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel); let state = self.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel);
state & STATE_SPAWNED != 0 state & STATE_SPAWNED != 0
} }
/// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> bool {
let old_state = self.state.fetch_or(STATE_TIMER_QUEUED, Ordering::AcqRel);
old_state & STATE_TIMER_QUEUED == 0
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::AcqRel);
}
} }

View File

@ -11,9 +11,8 @@ pub(crate) struct State {
spawned: AtomicBool, spawned: AtomicBool,
/// Task is in the executor run queue /// Task is in the executor run queue
run_queued: AtomicBool, run_queued: AtomicBool,
/// Task is in the executor timer queue
timer_queued: AtomicBool,
pad: AtomicBool, pad: AtomicBool,
pad2: AtomicBool,
} }
impl State { impl State {
@ -21,8 +20,8 @@ impl State {
Self { Self {
spawned: AtomicBool::new(false), spawned: AtomicBool::new(false),
run_queued: AtomicBool::new(false), run_queued: AtomicBool::new(false),
timer_queued: AtomicBool::new(false),
pad: AtomicBool::new(false), pad: AtomicBool::new(false),
pad2: AtomicBool::new(false),
} }
} }
@ -86,18 +85,4 @@ impl State {
self.run_queued.store(false, Ordering::Relaxed); self.run_queued.store(false, Ordering::Relaxed);
r r
} }
/// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> bool {
!self.timer_queued.swap(true, Ordering::Relaxed)
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.timer_queued.store(false, Ordering::Relaxed);
}
} }

View File

@ -6,9 +6,6 @@ use critical_section::Mutex;
pub(crate) const STATE_SPAWNED: u32 = 1 << 0; pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
/// Task is in the executor run queue /// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
/// Task is in the executor timer queue
#[cfg(feature = "integrated-timers")]
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
pub(crate) struct State { pub(crate) struct State {
state: Mutex<Cell<u32>>, state: Mutex<Cell<u32>>,
@ -72,22 +69,4 @@ impl State {
ok ok
}) })
} }
/// Mark the task as timer-queued. Return whether it was newly queued (i.e. not queued before)
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> bool {
self.update(|s| {
let ok = *s & STATE_TIMER_QUEUED == 0;
*s |= STATE_TIMER_QUEUED;
ok
})
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.update(|s| *s &= !STATE_TIMER_QUEUED);
}
} }

View File

@ -39,7 +39,7 @@ impl TimerQueue {
unsafe { unsafe {
let task = p.header(); let task = p.header();
let item = &task.timer_queue_item; let item = &task.timer_queue_item;
if task.state.timer_enqueue() { if item.next.get().is_none() {
// If not in the queue, add it and update. // If not in the queue, add it and update.
let prev = self.head.replace(Some(p)); let prev = self.head.replace(Some(p));
item.next.set(prev); item.next.set(prev);
@ -93,7 +93,7 @@ impl TimerQueue {
} else { } else {
// Remove it // Remove it
prev.set(item.next.get()); prev.set(item.next.get());
task.state.timer_dequeue(); item.next.set(None);
} }
} }
} }