Skip to main content

Call

Enum Call 

Source
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

§

PushCurrentTaskAtTheStartOfLIFOSharedQueue

Moves current shared task at the start of a shared LIFO task queue of the current executor.

§Safety

  • task must return Poll::Pending immediately 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_to must be a valid pointer to SyncTaskQueue

  • the reference must live at least as long as this state of the task

  • task must return Poll::Pending immediately 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_to must be a valid pointer to SyncTaskQueue

  • task must return Poll::Pending immediately 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_bool must be a valid pointer to AtomicBool

  • the AtomicBool must live at least as long as this state of the task

  • task must return Poll::Pending immediately 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 Fn must live at least as long as this state of the task.

  • task must return Poll::Pending immediately 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(())
    }
}

Implementations§

Source§

impl Call

Source

pub fn is_none(&self) -> bool

Returns true if the Call is None.

Trait Implementations§

Source§

impl Debug for Call

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Call

Source§

fn default() -> Call

Returns the “default value” for a type. Read more
Source§

impl Eq for Call

Source§

impl PartialEq for Call

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Call

§

impl !Send for Call

§

impl !Sync for Call

§

impl !UnwindSafe for Call

§

impl Freeze for Call

§

impl Unpin for Call

§

impl UnsafeUnpin for Call

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.