cib.h

Circular integer buffer interface.

This structure provides an organizational interface and combined with an memory array forms a circular buffer.

CIB_INIT( SIZE)

Initialize cib_t to a given size.

1
{ 0, 0, (SIZE) - 1 }
void cib_init(cib_t *__restrict cib, unsigned int size)

Initialize cib to 0 and set buffer size to size.

Parameters

cib:Buffer to initialize. Must not be NULL.
size:Size of the buffer, must not exceed MAXINT/2. Should be equal to 0 or power of 2.

unsigned int cib_avail(const cib_t * cib)

Calculates difference between cib.h::cib_put() and cib.h::cib_get() accesses.

Parameters

cib:the cib_t to check. Must not be NULL.

Return values

unsigned int cib_full(const cib_t * cib)

Check if cib is full.

Parameters

cib:the cib_t to check. Must not be NULL.

Return values

int cib_get(cib_t *__restrict cib)

Get the index of the next item in buffer.

Parameters

cib:corresponding cib to buffer. Must not be NULL.

Return values

  • index of next item, -1 if the buffer is empty
int cib_peek(cib_t *__restrict cib)

Get the index of the next item in buffer without removing it.

Parameters

cib:corresponding cib to buffer. Must not be NULL.

Return values

  • index of next item, -1 if the buffer is empty
int cib_get_unsafe(cib_t * cib)

Get the index of the next item in buffer.

Unsafe version, must not be called if buffer is empty!

Parameters

cib:corresponding cib to buffer. Must not be NULL.

Return values

  • index of next item
int cib_put(cib_t *__restrict cib)

Get index for item in buffer to put to.

Parameters

cib:corresponding cib to buffer. Must not be NULL.

Return values

  • index of item to put to, -1 if the buffer is full
int cib_put_unsafe(cib_t * cib)

Get index for item in buffer to put to.

Unsafe version, must not be called if buffer is full!

Parameters

cib:corresponding cib to buffer. Must not be NULL.

Return values

  • index of item to put to
struct cib_t

circular integer buffer structure

unsigned int read_count

number of (successful) read accesses

unsigned int write_count

number of (successful) write accesses

unsigned int mask

Size of buffer -1, i.e.

mask of the bits