Skip to main content

TaskRegistry

Struct TaskRegistry 

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

Public task registry facade used by executor lifecycle tracking and tests.

Registration and lookup take &self so the executor can share one registry without an outer mutex. Every spawn used to serialize on that mutex ahead of the lock-free scheduler: measured on an 8-core pin, executor spawn ran 3.18 M/s with one producer and fell to 2.97 M/s with eight, while the same scheduler reached without the registry rose from 6.18 M/s to 8.85 M/s.

The id counter is atomic, and the block directory takes its lock in read mode for the common path — a block is created once per 1024 ids, and slot insertion itself only needs &TaskStateBlock.

Storage is bounded by a RetentionPolicy when one is set: settled blocks are released, and TaskRegistry::is_completed keeps answering true for their tasks. Without a policy every block stays resident until TaskRegistry::cleanup_completed releases it.

Implementations§

Source§

impl TaskRegistry

Source

pub const fn new() -> Self

Create a registry that retains every task until it is cleaned up explicitly.

Source

pub fn with_retention(policy: RetentionPolicy) -> Self

Create a registry whose completed tasks are released under policy.

Source

pub fn register_task(&self) -> u64

Register a new task and return its ID.

The task stays queued until the caller drives it by id: TaskRegistry::mark_started, then TaskRegistry::mark_completed. Until it completes, its block is never retired, so both calls reach the task. Executor code that owns the task’s lifecycle uses a token instead.

Source

pub fn mark_started(&self, task_id: u64, worker_id: usize)

Mark a task as started.

Source

pub fn mark_completed(&self, task_id: u64)

Mark a task as completed.

Source

pub fn is_completed(&self, task_id: u64) -> bool

Check if a task is completed.

A task whose block was released under the retention policy is completed.

Source

pub fn completion(&self, task_id: u64) -> Option<bool>

Report whether a task completed, from one observation of the registry.

None is an id that was never registered. A task whose block was released under the retention policy is Some(true). A caller that must tell an unknown id from a finished one reads this once: two separate lookups can straddle the release of the task’s block.

Source

pub fn get_metadata(&self, task_id: u64) -> Option<TaskMetadata>

Get task metadata, or None for an unregistered task and for one whose metadata the retention policy already released.

Source

pub fn active_count(&self) -> usize

Get count of active tasks.

Source

pub fn completed_count(&self) -> usize

Get count of completed tasks whose state is still resident.

Source

pub fn register_waker(&self, task_id: u64, waker: &Waker) -> bool

Register a waker to be notified when the task completes.

Every distinct waker registered before completion is woken by it; a waker that will_wake one already registered is normally not added again (Waker::will_wake is best-effort). A task that already completed wakes the waker at once and keeps nothing. Returns false for an id the registry does not hold.

Source§

impl TaskRegistry

Source

pub fn cleanup_completed(&self, older_than: Duration) -> usize

Release every block whose tasks all completed at least older_than ago, returning how many blocks were released.

Every resident block is examined, including any that a concurrent automatic sweep has checked out; that sweep finds such a block already retired and moves on. The directory lock is held only to list the resident blocks and to retire the settled ones, never across a scan, so registrations proceed throughout. Automatic retention makes calling this unnecessary for an executor; it serves callers that manage a registry directly.

Trait Implementations§

Source§

impl Debug for TaskRegistry

Source§

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

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

impl Default for TaskRegistry

Source§

fn default() -> Self

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

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.