Expand description
Lock-free event transport between instrumented threads and background workers.
Each producing thread owns a chunked SPSC queue: it appends events into
fixed-size chunks with plain stores and publishes them with a single
Release store of the chunk’s len - no mutex, no RMW atomic on the hot
path. Chunks form a linked list, so the queue is unbounded.
A single consumer per registry (the subsystem’s background worker) sweeps
all registered queues periodically: it Acquire-loads each chunk’s len,
reads the published prefix, and frees fully consumed chunks. Producer and
consumer touch disjoint slot ranges by construction, so a queue is safe to
drain at any moment - including queues of threads parked at shutdown,
which is what guarantees a complete final report.
Safety invariants:
- Only the owning thread writes slots and the
len/nextof its tail chunk. - The consumer only reads slots below the published
lenand only frees a chunk after fully consuming it and observing itsnextpointer. - Single consumer per registry, enforced by the registry’s internal mutex (locked only at thread registration and during sweeps - never on the event hot path).
Structs§
- Event
Producer - The owning thread’s write handle, stored in a
thread_local. - Event
Queue - One thread’s event queue: a linked list of chunks. The owning thread
appends via its
EventProducer; the registry’s consumer drains. - Event
Queue Registry - All live per-thread queues for one event type, plus the gate that tells producers whether a worker is consuming.