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
impl TaskRegistry
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a registry that retains every task until it is cleaned up explicitly.
Sourcepub fn with_retention(policy: RetentionPolicy) -> Self
pub fn with_retention(policy: RetentionPolicy) -> Self
Create a registry whose completed tasks are released under policy.
Sourcepub fn register_task(&self) -> u64
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.
Sourcepub fn mark_started(&self, task_id: u64, worker_id: usize)
pub fn mark_started(&self, task_id: u64, worker_id: usize)
Mark a task as started.
Sourcepub fn mark_completed(&self, task_id: u64)
pub fn mark_completed(&self, task_id: u64)
Mark a task as completed.
Sourcepub fn is_completed(&self, task_id: u64) -> bool
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.
Sourcepub fn completion(&self, task_id: u64) -> Option<bool>
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.
Sourcepub fn get_metadata(&self, task_id: u64) -> Option<TaskMetadata>
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.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Get count of active tasks.
Sourcepub fn completed_count(&self) -> usize
pub fn completed_count(&self) -> usize
Get count of completed tasks whose state is still resident.
Sourcepub fn register_waker(&self, task_id: u64, waker: &Waker) -> bool
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
impl TaskRegistry
Sourcepub fn cleanup_completed(&self, older_than: Duration) -> usize
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.