Loading...
Searching...
No Matches
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.
 
static void cib_init (cib_t *__restrict cib, unsigned int size)
 Initialize cib to 0 and set buffer size to size.
 
static unsigned int cib_size (const cib_t *cib)
 Returns the total capacity (size parameter of cib_init()) of a cib_t.
 
static unsigned int cib_avail (const cib_t *cib)
 Calculates difference between cib_put() and cib_get() accesses.
 
static unsigned int cib_full (const cib_t *cib)
 Check if cib is full.
 
static int cib_get (cib_t *__restrict cib)
 Get the index of the next item in buffer.
 
static int cib_peek_at_unsafe (cib_t *__restrict cib, unsigned offset)
 Get the index of an item in the buffer without removing anything.
 
static int cib_peek_at (cib_t *__restrict cib, unsigned offset)
 Get the index of an item in the buffer without removing anything.
 
static int cib_peek_unsafe (cib_t *__restrict cib)
 Get the index of the next item in buffer without removing it.
 
static int cib_peek (cib_t *__restrict cib)
 Get the index of the next item in buffer without removing it.
 
static int cib_get_unsafe (cib_t *cib)
 Get the index of the next item in buffer.
 
static int cib_put (cib_t *__restrict cib)
 Get index for item in buffer to put to.
 
static int cib_put_unsafe (cib_t *cib)
 Get index for item in buffer to put to.
 

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 88 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 100 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
Return values
-1if the buffer is empty

Definition at line 113 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 202 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
Return values
-1if the buffer is empty

Definition at line 188 of file cib.h.

◆ cib_peek_at()

static int cib_peek_at ( cib_t *__restrict  cib,
unsigned  offset 
)
inlinestatic

Get the index of an item in the buffer without removing anything.

Offset 0 is the next item in the buffer that would be returned by cip_get(), offset 1 would be the following, and so on.

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
[in]offsetoffset from front of buffer
Returns
index of item
Return values
-1if no item at offset exists in the buffer

Definition at line 156 of file cib.h.

◆ cib_peek_at_unsafe()

static int cib_peek_at_unsafe ( cib_t *__restrict  cib,
unsigned  offset 
)
inlinestatic

Get the index of an item in the buffer without removing anything.

Offset 0 is the next item in the buffer that would be returned by cip_get(), offset 1 would be the following, and so on.

Unsafe version, must not pass an offset that is larger than the number of items currently in the buffer!

Parameters
[in,out]cibcorresponding cib to buffer. Must not be NULL.
[in]offsetoffset from front of buffer
Returns
index of item
Return values
-1if no item at offset exists in the buffer

Definition at line 138 of file cib.h.

◆ cib_peek_unsafe()

static int cib_peek_unsafe ( cib_t *__restrict  cib)
inlinestatic

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

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
Return values
-1if the buffer is empty

Definition at line 175 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
Return values
-1if the buffer is full

Definition at line 215 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 236 of file cib.h.

◆ cib_size()

static unsigned int cib_size ( const cib_t cib)
inlinestatic

Returns the total capacity (size parameter of cib_init()) of a cib_t.

Parameters
[in]cibthe cib_t to check. Must not be NULL.
Returns
The total size of cib.

Definition at line 76 of file cib.h.