stripes
nimony/lib/std/stripes.nim
type FifoStripe = object lock: SysLock head: int64 tail: int64 count: int64 data: seq[T]
proc init(s: var FifoStripe[T]; capacity: int64)proc tryEnqueue(s: var FifoStripe[T]; item: T): boolproc tryBulkEnqueue(s: var FifoStripe[T]; items: openArray[T]): int64Enqueue as many leading items of
items(in order) as fit under one lock acquisition; returns how many were taken.proc tryBulkDequeue(s: var FifoStripe[T]; bulkSize: int64; buf: var openArray[T]): int64proc grow(s: var FifoStripe[T]; newCapacity: int64)proc tryEnqueue(s: var FifoStripe[T]; item: T; maxCapacity: int64): boolLike
tryEnqueue, but a full stripe first doubles its capacity, up tomaxCapacity, so that a stripe can start small and still absorb a burst.type LocalRing = object head: int64 count: int64 data: seq[T] mask: int64
proc tryEnqueue(r: var LocalRing[T]; item: T; capacity: int64): boolPush
item;falsewhen the ring is full. Capacity is fixed at the first push (the ring starts empty, so no allocation is paid by a lane that never submits an op) and never changes: a full ring is backpressure for the caller, and reallocating would mean moving the elements of a ring that is being filled.proc tryBulkDequeue(r: var LocalRing[T]; bulkSize: int64; buf: var openArray[T]): int64Take up to
bulkSizeitems in FIFO order; 0 when the ring is empty.