Class LatestFrameSlot
Lock-free, allocation-free "latest value wins" handoff for one multi-channel frame, for the
latest-only monitors (spider, heatmap) that render only the newest sample each flush.
Why: these monitors push a frame per sample but the flush keeps only the last one,
so a queue is pure waste. This slot keeps exactly the newest frame in pre-allocated buffers —
the producer overwrites, the consumer reads the latest. Steady-state allocates nothing.
SPSC triple buffer: one producer calls Write(ReadOnlySpan<double>); one consumer calls
TryReadInto(Span<double>)/HasData/Clear(). Three buffers — the producer
always owns one (back), the consumer always owns one (front), and a shared "ready" slot (middle)
is swapped via a single atomic. The producer and consumer never touch the same buffer, so reads
are tear-free and wait-free; intermediate frames are simply skipped. NOT safe for multiple producers.
Inheritance
LatestFrameSlot
Assembly: MOSAIC.dll
Syntax
public sealed class LatestFrameSlot
Constructors
LatestFrameSlot(int)
Declaration
public LatestFrameSlot(int channels)
Parameters
| Type |
Name |
Description |
| int |
channels |
|
Fields
_buffers
The three reusable frame buffers.
Declaration
private readonly double[][] _buffers
Field Value
_channels
Declaration
private readonly int _channels
Field Value
_flags
Packed indices in one atomic int:
bits 0-1 = front (consumer's), bits 2-3 = middle (ready/spare),
bits 4-5 = back (producer's), bit 6 (0x40) = dirty (new frame ready).
Declaration
Field Value
_readIndex
Declaration
Field Value
_writeIndex
Declaration
Field Value
Properties
Channels
Channels (doubles) per frame.
Declaration
public int Channels { get; }
Property Value
HasData
True if a frame newer than the last read is waiting. Consumer thread only.
Declaration
public bool HasData { get; }
Property Value
Methods
Clear()
Declaration
TryReadInto(Span<double>)
Copies the latest frame into dest (≥ Channels long) and
returns true, or returns false if nothing new since the last read. Consumer thread only.
Declaration
public bool TryReadInto(Span<double> dest)
Parameters
Returns
Write(ReadOnlySpan<double>)
Writes one frame, becoming the new "latest". Producer thread only.
Declaration
public void Write(ReadOnlySpan<double> frame)
Parameters