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:
- N is bounded (default 1024)
- Registration/unregistration are infrequent compared to strand work
- No locks means no contention, just atomic ops
Fields§
§overflow_count: AtomicU64Number of slots that couldn’t be registered (registry full)
Implementations§
Source§impl StrandRegistry
impl StrandRegistry
Sourcepub fn register(&self, strand_id: u64) -> Option<usize>
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).
Sourcepub fn unregister(&self, strand_id: u64) -> bool
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).
Sourcepub fn active_strands(&self) -> impl Iterator<Item = (u64, u64)> + '_
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.