Skip to content

internal/slot_encoding

Internal module

lockfree/internal/slot_encoding is an internal module. Its API is not part of the umbrella's semver contract and may change at any time. Downstream code MUST NOT import it directly. Documented here for contributors and reviewers.

slot_encoding defines the bit-level layout for the unbounded MPMC shape's (seq, payload) packed cell — the DWCAS word used by the LCRQ paper §4 close-CAS-on-empty progress rule. It centralizes the encode / decode pair so that the producer and consumer paths agree on the layout, and so that the supportsCopyMem(T) AND sizeof(T) <= 8 constraint on unbounded-MPMC payload T can be statically enforced in one place.

See also

  • Queue — the unbounded queue that consumes this encoding for its MPMC shape.

slot_encoding

SlotEncoding[T] — compile-time mapping from user-facing T to encoded slot type.

Unified encoding: ref X -> ManagedRef[X] (8B distinct uint; refcount lifecycle) string -> ManagedSlice[char] (8B distinct uint; box pointer) seq[U] -> ManagedSlice[U] (8B distinct uint; box pointer) POD T -> T (identity; assumed sizeof(T) <= sizeof(uint))

Cells in Segment + MPMCCellArrayN are typed LCRQCell[SlotEncoding(T)] / MPMCCell[SlotEncoding(T)].

Internal-only. NEVER user-facing. The user writes Queue[ref Foo, ...], Queue[string, ...], or Queue[seq[int], ...]; this template performs the wire-format substitution invisibly inside the queue cores.

SlotEncoding

template SlotEncoding(T: typedesc): typedesc

Map a user-facing payload type T to its slot-encoded wire type.

Type-extraction grammar (verified under Nim 2.2.10): * typeof(default(T)[]) — pointee of ref X * typeof(default(T)[0]) — element of seq[U].

Parameters
  • T (typedesc)
Returns

typedesc