maitake::scheduler

Struct LocalStaticScheduler

Source
pub struct LocalStaticScheduler { /* private fields */ }
Expand description

A statically-initialized scheduler for !Send tasks.

This type is identical to the StaticScheduler type, except that it is capable of scheduling Futures that do not implement Send. Because this scheduler’s futures cannot be moved across threads1, the scheduler itself is also !Send and !Sync, as ticking it from another thread would cause its tasks to be polled from that thread, violating the Send and Sync contracts.


  1. Or CPU cores, in bare-metal systems. 

Implementations§

Source§

impl LocalStaticScheduler

Source

pub const DEFAULT_TICK_SIZE: usize = 256usize

How many tasks are polled per call to LocalStaticScheduler::tick.

Chosen by fair dice roll, guaranteed to be random.

Source

pub const unsafe fn new_with_static_stub(stub: &'static TaskStub) -> Self

Create a LocalStaticScheduler with a static “stub” task entity

This is used for creating a LocalStaticScheduler as a static variable.

§Safety

The “stub” provided must ONLY EVER be used for a single LocalStaticScheduler. Re-using the stub for multiple schedulers may lead to undefined behavior.

For a safe alternative, consider using the new_static! macro to initialize a LocalStaticScheduler in a static variable.

Source

pub fn spawn_allocated<F, STO>( &'static self, task: STO::StoredTask, ) -> JoinHandle<F::Output>
where F: Future + 'static, F::Output: 'static, STO: Storage<&'static Self, F>,

Spawn a pre-allocated, Send task.

Unlike StaticScheduler::spawn_allocated, this method is capable of spawning Futures which do not implement Send.

This method is used to spawn a task that requires some bespoke procedure of allocation, typically of a custom Storage implementor. See the documentation for the Storage trait for more details on using custom task storage.

This method returns a JoinHandle that can be used to await the task’s output. Dropping the JoinHandle detaches the spawned task, allowing it to run in the background without awaiting its output.

When tasks are spawned on a scheduler, the scheduler must be ticked in order to drive those tasks to completion. See the module-level documentation for more information on implementing a system’s run loop.

Source

pub fn build_task<'a>(&'static self) -> Builder<'a, &'static Self>

Returns a new task Builder for configuring tasks prior to spawning them on this scheduler.

To spawn !Send tasks using a Builder, use the Builder::spawn_local method.

Source

pub fn current_task(&'static self) -> Option<TaskRef>

Returns a TaskRef referencing the task currently being polled by this scheduler, if a task is currently being polled.

§Returns
  • Some(TaskRef) referencing the currently-polling task, if a task is currently being polled (i.e., the scheduler is ticking and the queue of scheduled tasks is non-empty).

  • None if the scheduler is not currently being polled (i.e., the scheduler is not ticking or its run queue is empty and all polls have completed).

Source

pub fn tick(&'static self) -> Tick

Tick this scheduler, polling up to Self::DEFAULT_TICK_SIZE tasks from the scheduler’s run queue.

Only a single CPU core/thread may tick a given scheduler at a time. If another call to tick is in progress on a different core, this method will immediately return.

See the module-level documentation for more information on using this function to implement a system’s run loop.

§Returns

A Tick struct with data describing what occurred during the scheduler tick.

Source

pub fn spawner(&'static self) -> LocalStaticSpawner

Returns a new LocalStaticSpawner that can be used by other threads to spawn Send tasks on this scheduler.

Source§

impl LocalStaticScheduler

Source

pub fn new() -> Self

Returns a new LocalStaticScheduler with a heap-allocated stub task.

Unlike LocalStaticScheduler::new_with_static_stub, this is not a const fn, as it performs a heap allocation for the stub task. However, the returned StaticScheduler must still be stored in a static variable in order to be used.

This method is generally used with lazy initialization of the scheduler static.

Source

pub fn spawn<F>(&'static self, future: F) -> JoinHandle<F::Output>
where F: Future + 'static, F::Output: 'static,

Spawn a task.

This method returns a JoinHandle that can be used to await the task’s output. Dropping the JoinHandle detaches the spawned task, allowing it to run in the background without awaiting its output.

When tasks are spawned on a scheduler, the scheduler must be ticked in order to drive those tasks to completion. See the module-level documentation for more information on implementing a system’s run loop.

Trait Implementations§

Source§

impl Debug for LocalStaticScheduler

Source§

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

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

impl Default for LocalStaticScheduler

Source§

fn default() -> LocalStaticScheduler

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

impl Schedule for &'static LocalStaticScheduler

Source§

fn schedule(&self, task: TaskRef)

Schedule a task on this scheduler. Read more
Source§

fn current_task(&self) -> Option<TaskRef>

Returns a TaskRef referencing the task currently being polled by this scheduler, if a task is currently being polled.
Source§

fn build_task<'a>(&self) -> Builder<'a, Self>

Returns a new task Builder for configuring tasks prior to spawning them on this scheduler.

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.