StrandRegistry

Struct StrandRegistry 

Source
pub struct StrandRegistry {
    pub overflow_count: AtomicU64,
    /* private fields */
}
Expand description

Lock-free strand registry

Provides O(n) registration (scan for free slot) and O(n) unregistration. This is acceptable because:

  1. N is bounded (default 1024)
  2. Registration/unregistration are infrequent compared to strand work
  3. No locks means no contention, just atomic ops

Fields§

§overflow_count: AtomicU64

Number of slots that couldn’t be registered (registry full)

Implementations§

Source§

impl StrandRegistry

Source

pub fn register(&self, strand_id: u64) -> Option<usize>

Register a strand, returning the slot index if successful

Uses CAS to atomically claim a free slot. Returns None if the registry is full (strand still runs, just not tracked).

Source

pub fn unregister(&self, strand_id: u64) -> bool

Unregister a strand by ID

Scans for the slot containing this strand ID and clears it. Returns true if found and cleared, false if not found.

Note: ABA problem is not a concern here because strand IDs are monotonically increasing u64 values. ID reuse would require 2^64 spawns, which is practically impossible (at 1 billion spawns/sec, it would take ~584 years).

Source

pub fn active_strands(&self) -> impl Iterator<Item = (u64, u64)> + '_

Iterate over active strands (for diagnostics)

Returns an iterator of (strand_id, spawn_time) for non-empty slots. Note: This is a snapshot and may be slightly inconsistent due to concurrent updates.

Source

pub fn capacity(&self) -> usize

Get the registry capacity

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.