add STATE_ELIGIBLE const for 0, use instead of literal 0
This commit is contained in:
parent
80d7193b5b
commit
6c53ca072a
@ -34,6 +34,8 @@ use self::util::{SyncUnsafeCell, UninitCell};
|
|||||||
pub use self::waker::task_from_waker;
|
pub use self::waker::task_from_waker;
|
||||||
use super::SpawnToken;
|
use super::SpawnToken;
|
||||||
|
|
||||||
|
/// Task is eligible for allocation
|
||||||
|
pub(crate) const STATE_ELIGIBLE: u32 = 0;
|
||||||
/// 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
|
||||||
@ -116,7 +118,7 @@ impl<F: Future + 'static> TaskStorage<F> {
|
|||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
raw: TaskHeader {
|
raw: TaskHeader {
|
||||||
state: AtomicU32::new(0),
|
state: AtomicU32::new(STATE_ELIGIBLE),
|
||||||
run_queue_item: RunQueueItem::new(),
|
run_queue_item: RunQueueItem::new(),
|
||||||
executor: SyncUnsafeCell::new(None),
|
executor: SyncUnsafeCell::new(None),
|
||||||
// Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss`
|
// Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss`
|
||||||
@ -195,7 +197,12 @@ impl<F: Future + 'static> AvailableTask<F> {
|
|||||||
pub fn claim(task: &'static TaskStorage<F>) -> Option<Self> {
|
pub fn claim(task: &'static TaskStorage<F>) -> Option<Self> {
|
||||||
task.raw
|
task.raw
|
||||||
.state
|
.state
|
||||||
.compare_exchange(0, STATE_SPAWNED | STATE_RUN_QUEUED, Ordering::AcqRel, Ordering::Acquire)
|
.compare_exchange(
|
||||||
|
STATE_ELIGIBLE,
|
||||||
|
STATE_SPAWNED | STATE_RUN_QUEUED,
|
||||||
|
Ordering::AcqRel,
|
||||||
|
Ordering::Acquire,
|
||||||
|
)
|
||||||
.ok()
|
.ok()
|
||||||
.map(|_| Self { task })
|
.map(|_| Self { task })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user