pub struct RegionTree { /* private fields */ }Expand description
Tree of regions enforcing structured concurrency (§4.11).
Every task/actor must be region-owned. The tree enforces INV-REGION-QUIESCENCE: no region closes until all children complete, all finalizers run, and all obligations resolve.
Implementations§
Source§impl RegionTree
impl RegionTree
Sourcepub fn create_root(
&mut self,
kind: RegionKind,
cx: Cx<FullCaps>,
) -> Result<Region>
pub fn create_root( &mut self, kind: RegionKind, cx: Cx<FullCaps>, ) -> Result<Region>
Create the root region.
Only one root region may exist. Returns an error if a root already exists.
Sourcepub fn create_child(
&mut self,
parent: Region,
kind: RegionKind,
cx: Cx<FullCaps>,
) -> Result<Region>
pub fn create_child( &mut self, parent: Region, kind: RegionKind, cx: Cx<FullCaps>, ) -> Result<Region>
Create a child region under the given parent.
Sourcepub fn kind(&self, id: Region) -> Option<RegionKind>
pub fn kind(&self, id: Region) -> Option<RegionKind>
Query the kind of a region.
Sourcepub fn state(&self, id: Region) -> Option<RegionState>
pub fn state(&self, id: Region) -> Option<RegionState>
Query the state of a region.
Sourcepub fn cx(&self, id: Region) -> Option<Cx<FullCaps>>
pub fn cx(&self, id: Region) -> Option<Cx<FullCaps>>
Get a clone of the region’s Cx for cancellation inspection.
Sourcepub fn active_tasks(&self, id: Region) -> usize
pub fn active_tasks(&self, id: Region) -> usize
Active task count for a region.
Sourcepub fn active_obligations(&self, id: Region) -> usize
pub fn active_obligations(&self, id: Region) -> usize
Active obligation count for a region.
Sourcepub fn register_task(&self, id: Region) -> Result<TaskHandle>
pub fn register_task(&self, id: Region) -> Result<TaskHandle>
Register a task in a region, returning an RAII handle.
The task count is incremented; when the handle is dropped, it decrements.
Returns Err(Busy) if the region is not RegionState::Open.
Sourcepub fn register_obligation(&self, id: Region) -> Result<ObligationHandle>
pub fn register_obligation(&self, id: Region) -> Result<ObligationHandle>
Register an obligation in a region, returning an RAII handle.
Obligations can be registered while the region is Open or Closing
(to allow in-flight work to create follow-up obligations during drain).
Returns Err(Busy) if the region is RegionState::Closed.
Sourcepub fn register_finalizer(
&mut self,
id: Region,
finalizer: impl FnOnce() + Send + 'static,
) -> Result<()>
pub fn register_finalizer( &mut self, id: Region, finalizer: impl FnOnce() + Send + 'static, ) -> Result<()>
Register a finalizer callback to run during region close.
Sourcepub fn begin_close(&mut self, id: Region) -> Result<()>
pub fn begin_close(&mut self, id: Region) -> Result<()>
Begin closing a region: cancel its Cx and set state to Closing.
Recursively begins close on all descendant regions (parent-first cancellation propagation per INV-CANCEL-PROPAGATES).
Does NOT wait for quiescence. Use is_quiescent
to poll, then complete_close to finalize.
Sourcepub fn is_quiescent(&self, id: Region) -> bool
pub fn is_quiescent(&self, id: Region) -> bool
Check whether a region has reached quiescence.
A region is quiescent when:
- all child regions are
RegionState::Closed, - active task count is zero,
- active obligation count is zero.
Sourcepub fn complete_close(&mut self, id: Region) -> Result<()>
pub fn complete_close(&mut self, id: Region) -> Result<()>
Complete region close: run finalizers and mark as RegionState::Closed.
Returns an error if the region is not quiescent.
Sourcepub fn close_and_drain(&mut self, id: Region) -> Result<()>
pub fn close_and_drain(&mut self, id: Region) -> Result<()>
Close a region and spin-wait until quiescent, then finalize.
This is the full close protocol: cancel → drain → finalize. Blocks the caller until INV-REGION-QUIESCENCE is satisfied. Children are drained bottom-up before the parent.