Remove TIMER_QUEUED
This commit is contained in:
parent
a8617429e4
commit
c90d048ecb
@ -1,7 +1,5 @@
|
|||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
use super::timer_queue::TimerEnqueueOperation;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(crate) struct Token(());
|
pub(crate) struct Token(());
|
||||||
|
|
||||||
@ -16,8 +14,6 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
|
|||||||
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
|
|
||||||
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
|
|
||||||
|
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
state: AtomicU32,
|
state: AtomicU32,
|
||||||
@ -71,32 +67,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 can be enqueued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
|
|
||||||
if self
|
|
||||||
.state
|
|
||||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| {
|
|
||||||
// If not started, ignore it
|
|
||||||
if state & STATE_SPAWNED == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
// Mark it as enqueued
|
|
||||||
Some(state | STATE_TIMER_QUEUED)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
TimerEnqueueOperation::Enqueue
|
|
||||||
} else {
|
|
||||||
TimerEnqueueOperation::Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unmark the task as timer-queued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_dequeue(&self) {
|
|
||||||
self.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering};
|
use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering};
|
||||||
|
|
||||||
use super::timer_queue::TimerEnqueueOperation;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(crate) struct Token(());
|
pub(crate) struct Token(());
|
||||||
|
|
||||||
@ -16,7 +14,6 @@ pub(crate) fn locked<R>(f: impl FnOnce(Token) -> R) -> R {
|
|||||||
// Must be kept in sync with the layout of `State`!
|
// Must be kept in sync with the layout of `State`!
|
||||||
pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
|
pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
|
||||||
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 8;
|
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 8;
|
||||||
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 16;
|
|
||||||
|
|
||||||
#[repr(C, align(4))]
|
#[repr(C, align(4))]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
@ -24,9 +21,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 {
|
||||||
@ -34,8 +30,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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,32 +97,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 can be enqueued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
|
|
||||||
if self
|
|
||||||
.as_u32()
|
|
||||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |state| {
|
|
||||||
// If not started, ignore it
|
|
||||||
if state & STATE_SPAWNED == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
// Mark it as enqueued
|
|
||||||
Some(state | STATE_TIMER_QUEUED)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
TimerEnqueueOperation::Enqueue
|
|
||||||
} else {
|
|
||||||
TimerEnqueueOperation::Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unmark the task as timer-queued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_dequeue(&self) {
|
|
||||||
self.timer_queued.store(false, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,10 @@ use core::cell::Cell;
|
|||||||
pub(crate) use critical_section::{with as locked, CriticalSection as Token};
|
pub(crate) use critical_section::{with as locked, CriticalSection as Token};
|
||||||
use critical_section::{CriticalSection, Mutex};
|
use critical_section::{CriticalSection, Mutex};
|
||||||
|
|
||||||
use super::timer_queue::TimerEnqueueOperation;
|
|
||||||
|
|
||||||
/// Task is spawned (has a future)
|
/// Task is spawned (has a future)
|
||||||
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
|
|
||||||
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>>,
|
||||||
@ -81,25 +77,4 @@ impl State {
|
|||||||
ok
|
ok
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark the task as timer-queued. Return whether it can be enqueued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
|
|
||||||
self.update(|s| {
|
|
||||||
// FIXME: we need to split SPAWNED into two phases, to prevent enqueueing a task that is
|
|
||||||
// just being spawned, because its executor pointer may still be changing.
|
|
||||||
if *s & STATE_SPAWNED == STATE_SPAWNED {
|
|
||||||
*s |= STATE_TIMER_QUEUED;
|
|
||||||
TimerEnqueueOperation::Enqueue
|
|
||||||
} else {
|
|
||||||
TimerEnqueueOperation::Ignore
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unmark the task as timer-queued.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn timer_dequeue(&self) {
|
|
||||||
self.update(|s| *s &= !STATE_TIMER_QUEUED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user