elpekenin/utils/ring_buffer.h

Implementation of a ring buffer.

Tiny wrapper on top of an array.


new_rbuf(type, size, name)
[source]

Create a new ring buffer.

Parameters:
  • type – Of the values being stored.

  • size – Capacity of the buffer.

  • name – Of the ring buffer variable to be created.

rbuf_push(rbuf, value)
[source]

Insert an element into a buffer.

rbuf_pop(rbuf, max, dest)
[source]

Read data from a buffer.

Parameters:
  • rbuf – The ring buffer.

  • max – Elements to be read at most. 0 -> Read everything

  • dest – Memory where data is read.

Returns:

Number of bytes read.

rbuf_clear(rbuf)
[source]

Mark a buffer as empty.

Note

Does not zero out the memory.

rbuf_size(rbuf)
[source]

Get the size of a buffer.

rbuf_full(rbuf)
[source]

Check if the buffer is completely filled.