std1.0.0-beta-7 SafeC docs

std :: collections::ringbuffer

Struct std::RingBuffer

#include <std/collections/ringbuffer.h> source

struct RingBuffer {
    []unsigned char buf;
    unsigned long cap;
    unsigned long mask;
    volatile unsigned long head;
    volatile unsigned long tail;
}

Fields

§[]unsigned char bufsource

backing store (set by RingBuffer::over)

§unsigned long capsource

capacity in bytes (must be power of two)

§unsigned long masksource

cap - 1

§volatile unsigned long headsource

write position (producer)

§volatile unsigned long tailsource

read position (consumer)

Methods

§static struct RingBuffer over([]unsigned char buf)source · definition

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.

§unsigned long length() constsource · definition

Return number of bytes currently readable.

§unsigned long writable() constsource · definition

Return number of bytes that can be written without blocking.

§int is_empty() constsource · definition

Return 1 if empty.

§int is_full() constsource · definition

Return 1 if full.

§unsigned long write([]const unsigned char data)source · definition

Write as much of data as fits. Returns bytes actually written.

§unsigned long read([]unsigned char out)source · definition

Read up to out.len bytes into out. Returns bytes actually read.

§unsigned long peek([]unsigned char out) constsource · definition

Like read, without consuming. Returns bytes copied.

§int enqueue(unsigned char b)source · definition

One byte at a time (the Fifo protocol, std/collections/traits.h): enqueue returns 1, or 0 if full; dequeue returns null if empty.

§?unsigned char dequeue()source · definition
§unsigned long discard(unsigned long len)source · definition

Discard len bytes. Returns bytes discarded.

§void clear()source · definition

Reset (empty) the buffer. Safe only when no concurrent access.