pub enum Call {
None,
PushCurrentTaskAtTheStartOfLIFOSharedQueue,
PushCurrentTaskTo(*const SyncTaskList),
PushCurrentTaskToAndRemoveItIfCounterIsZero(*const SyncTaskList, *const AtomicUsize, Ordering),
ReleaseAtomicBool(*const CachePadded<AtomicBool>),
PushFnToThreadPool(*mut dyn Fn()),
ChangeCurrentTaskLocality(Locality),
}Expand description
Represents a call from a Future::poll to the Executor.
The Call enum encapsulates different actions that an executor can take
after a future yields Poll::Pending.
These actions may involve scheduling
the current task, signaling readiness, or interacting with sync primitives.
§Safety
After invoking a Call, the associated future must return Poll::Pending immediately.
The action defined by the Call will be executed after the future returns, ensuring
that it is safe to perform state transitions or task scheduling without directly affecting
the current state of the future. Use this mechanism only if you fully understand the
implications and safety concerns of moving a future between different states or threads.
Variants§
None
Does nothing
Moves current shared task at the start of a shared LIFO
task queue of the current executor.
§Safety
-
task must return
Poll::Pendingimmediately after calling this function -
calling task must be shared (else you don’t need any
Calls)
PushCurrentTaskTo(*const SyncTaskList)
Pushes current task to the given AtomicTaskList.
§Safety
-
send_tomust be a valid pointer toSyncTaskQueue -
the reference must live at least as long as this state of the task
-
task must return
Poll::Pendingimmediately after calling this function -
calling task must be shared (else you don’t need any
Calls)
PushCurrentTaskToAndRemoveItIfCounterIsZero(*const SyncTaskList, *const AtomicUsize, Ordering)
Pushes current task to the given AtomicTaskList and removes it if the given AtomicUsize
is 0 with given Ordering after removing executes it.
§Safety
-
send_tomust be a valid pointer toSyncTaskQueue -
task must return
Poll::Pendingimmediately after calling this function -
counter must be a valid pointer to
AtomicUsize -
the references must live at least as long as this state of the task
-
calling task must be shared (else you don’t need any
Calls)
ReleaseAtomicBool(*const CachePadded<AtomicBool>)
Stores false for the given AtomicBool with Release ordering.
§Safety
-
atomic_boolmust be a valid pointer toAtomicBool -
the
AtomicBoolmust live at least as long as this state of the task -
task must return
Poll::Pendingimmediately after calling this function -
calling task must be shared (else you don’t need any
Calls)
PushFnToThreadPool(*mut dyn Fn())
Pushes f to the blocking pool.
§Safety
-
the
Fnmust live at least as long as this state of the task. -
task must return
Poll::Pendingimmediately after calling this function -
calling task must be shared (else you don’t need any
Calls)
ChangeCurrentTaskLocality(Locality)
Changes current task locality and wakes up current task.
§Example
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use orengine::local_executor;
use orengine::runtime::call::Call;
use orengine::runtime::Locality;
struct UpdateCurrentTaskLocality {
locality: Locality,
was_called: bool,
}
impl Future for UpdateCurrentTaskLocality {
type Output = ();
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
let this = unsafe { self.get_unchecked_mut() };
if !this.was_called {
this.was_called = true;
unsafe {
local_executor().invoke_call(Call::ChangeCurrentTaskLocality(this.locality));
};
return Poll::Pending;
}
Poll::Ready(())
}
}