AvailableTask::claim sets STATE_CLAIMED; STATE_SPAWNED set only after init

This commit is contained in:
Hailey Somerville 2023-09-14 13:45:57 +10:00
parent c4987b12a1
commit 63d54c6a62

View File

@ -199,12 +199,7 @@ impl<F: Future + 'static> AvailableTask<F> {
pub fn claim(task: &'static TaskStorage<F>) -> Option<Self> {
task.raw
.state
.compare_exchange(
STATE_ELIGIBLE,
STATE_SPAWNED | STATE_RUN_QUEUED,
Ordering::AcqRel,
Ordering::Acquire,
)
.compare_exchange(STATE_ELIGIBLE, STATE_CLAIMED, Ordering::AcqRel, Ordering::Acquire)
.ok()
.map(|_| Self { task })
}
@ -214,6 +209,11 @@ impl<F: Future + 'static> AvailableTask<F> {
self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll));
self.task.future.write_in_place(future);
self.task
.raw
.state
.store(STATE_SPAWNED | STATE_RUN_QUEUED, Ordering::Release);
let task = TaskRef::new(self.task);
SpawnToken::new(task)