cib.h File Reference

Circular integer buffer interface. More...

Detailed Description

Circular integer buffer interface.

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

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file cib.h.

#include "assert.h"
+ Include dependency graph for cib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cib_t
 circular integer buffer structure More...
 
#define CIB_INIT(SIZE)   { 0, 0, (SIZE)-1 }
 Initialize cib_t to a given size. More...
 
static void cib_init (cib_t *__restrict cib, unsigned int size)
 Initialize cib to 0 and set buffer size to size. More...
 
static unsigned int cib_avail (const cib_t *cib)
 Calculates difference between cib_put() and cib_get() accesses. More...
 
static unsigned int cib_full (const cib_t *cib)
 Check if cib is full. More...
 
static int cib_get (cib_t *__restrict cib)
 Get the index of the next item in buffer. More...
 
static int cib_peek (cib_t *__restrict cib)
 Get the index of the next item in buffer without removing it. More...
 
static int cib_get_unsafe (cib_t *cib)
 Get the index of the next item in buffer. More...
 
static int cib_put (cib_t *__restrict cib)
 Get index for item in buffer to put to. More...
 
static int cib_put_unsafe (cib_t *cib)
 Get index for item in buffer to put to. More...
 

Macro Definition Documentation

◆ CIB_INIT

#define CIB_INIT (   SIZE)    { 0, 0, (SIZE)-1 }

Initialize cib_t to a given size.

Parameters
[in]SIZESize of the buffer, must not exceed (UINT_MAX + 1) / 2. Should be equal to 0 or power of 2.

Definition at line 47 of file cib.h.

Function Documentation

◆ cib_avail()

static unsigned int cib_avail ( const cib_t cib)
inlinestatic

Calculates difference between cib_put() and cib_get() accesses.

Parameters
[in]cibthe cib_t to check. Must not be NULL.
Returns
How often cib_get() can be called before cib is empty.

Definition at line 74 of file cib.h.

◆ cib_full()

static unsigned int cib_full ( const cib_t cib)
inlinestatic

Check if cib is full.

Parameters
[in]cibthe cib_t to check. Must not be NULL.
Returns
1 if cib_put() would return "-1", 0 otherwise

Definition at line 86 of file cib.h.

◆ cib_get()

static int cib_get ( cib_t *__restrict  cib)
inlinestatic

Get the index of the next item in buffer.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item, -1 if the buffer is empty

Definition at line 98 of file cib.h.

◆ cib_get_unsafe()

static int cib_get_unsafe ( cib_t cib)
inlinestatic

Get the index of the next item in buffer.

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

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item

Definition at line 132 of file cib.h.

◆ cib_init()

static void cib_init ( cib_t *__restrict  cib,
unsigned int  size 
)
inlinestatic

Initialize cib to 0 and set buffer size to size.

Parameters
[out]cibBuffer to initialize. Must not be NULL.
[in]sizeSize of the buffer, must not exceed (UINT_MAX + 1) / 2. Should be equal to 0 or power of 2.

Definition at line 58 of file cib.h.

◆ cib_peek()

static int cib_peek ( cib_t *__restrict  cib)
inlinestatic

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

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of next item, -1 if the buffer is empty

Definition at line 114 of file cib.h.

◆ cib_put()

static int cib_put ( cib_t *__restrict  cib)
inlinestatic

Get index for item in buffer to put to.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of item to put to, -1 if the buffer is full

Definition at line 144 of file cib.h.

◆ cib_put_unsafe()

static int cib_put_unsafe ( cib_t cib)
inlinestatic

Get index for item in buffer to put to.

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

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
Returns
index of item to put to

Definition at line 165 of file cib.h.