std :: collections::ringbuffer
Struct std::RingBuffer
struct RingBuffer {
[]unsigned char buf;
unsigned long cap;
unsigned long mask;
volatile unsigned long head;
volatile unsigned long tail;
}Fields
backing store (set by RingBuffer::over)
capacity in bytes (must be power of two)
cap - 1
write position (producer)
read position (consumer)
Methods
Initialise over an existing backing store, which must outlive the ring (a static array, typically); its length is rounded down to a power of two for the capacity.
Return number of bytes currently readable.
Return number of bytes that can be written without blocking.
Return 1 if empty.
Return 1 if full.
Write as much of data as fits. Returns bytes actually written.
Read up to out.len bytes into out. Returns bytes actually read.
Like read, without consuming. Returns bytes copied.
One byte at a time (the Fifo protocol, std/collections/traits.h): enqueue returns 1, or 0 if full; dequeue returns null if empty.
Discard len bytes. Returns bytes discarded.
Reset (empty) the buffer. Safe only when no concurrent access.