pub struct ArrayLinks<const N: usize> { /* private fields */ }Expand description
An owned [AtomicU32; N] link backing (used inside the fused
ArrayIndexStack; slot-resident implementors host their own links
instead). Every link starts at 0 — matching OS-zeroed backing — and is
only ever written by a push (no eager free-list chaining).
§Layout note — link-array false sharing
Each link is a 4-byte AtomicU32, so 16 consecutive indices share one
64-byte cache line. If indices from the same 16-index group are handed to
different threads under contention, this array becomes a SECOND contended
surface alongside the stack’s own head — contended by accident of index
numbering, not by design. Fix it at the CALLER when a profile shows it:
wrap the index-to-link mapping so contended indices land in different
groups, use a #[repr(align(64))] newtype per link, or — this crate’s own
README’s recommendation for production — host links slot-resident inside a
larger per-slot struct. Do NOT pad ArrayLinks itself to one link per
cache line: that would multiply its footprint 16x for every
single-threaded (or contention-indifferent) caller.
Implementations§
Source§impl<const N: usize> ArrayLinks<N>
impl<const N: usize> ArrayLinks<N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct N links, every one at 0. NOT a bulk free-list init — links
only become meaningful once their index is pushed. Under
--cfg loom this cannot be const (loom’s atomics have no const ctor).
Sourcepub fn load_next(&self, index: u32) -> u32
pub fn load_next(&self, index: u32) -> u32
Load the “next” link for index with Acquire ordering.
This Acquire — and store_next’s Release — is
deliberately retained rather than weakened to Relaxed, which the
stack’s own head-publication proof would permit: defence-in-depth, see
StackStorage’s “Ordering contract”.
§Panics
Panics if index >= N; the owned stack also checks this backing bound
after its head-word range check.
Sourcepub fn store_next(&self, index: u32, next: u32)
pub fn store_next(&self, index: u32, next: u32)
Store the “next” link for index with Release ordering. This is the
ONLY write the stack makes to link storage, and only during a push — the
lazy-link discipline: link storage is never eagerly initialised.
Like load_next’s Acquire, this Release is
deliberate defence-in-depth, not a stack-proof requirement — see
StackStorage’s “Ordering contract”.
§Panics
Panics if index >= N — the same bound as
load_next.