Contiki-NG
Functions
ringbufindex.c File Reference

    ringbufindex library.
More...

#include <string.h>
#include "lib/ringbufindex.h"

Go to the source code of this file.

Functions

void ringbufindex_init (struct ringbufindex *r, uint8_t size)
 Initialize a ring buffer. More...
 
int ringbufindex_put (struct ringbufindex *r)
 Put one element to the ring buffer. More...
 
int ringbufindex_peek_put (const struct ringbufindex *r)
 Check if there is space to put an element. More...
 
int ringbufindex_get (struct ringbufindex *r)
 Remove the first element and return its index. More...
 
int ringbufindex_peek_get (const struct ringbufindex *r)
 Return the index of the first element which will be removed if calling ringbufindex_get. More...
 
int ringbufindex_size (const struct ringbufindex *r)
 Return the ring buffer size. More...
 
int ringbufindex_elements (const struct ringbufindex *r)
 Return the number of elements currently in the ring buffer. More...
 
int ringbufindex_full (const struct ringbufindex *r)
 Is the ring buffer full? More...
 
int ringbufindex_empty (const struct ringbufindex *r)
 Is the ring buffer empty? More...
 

Detailed Description

    ringbufindex library.

Implements basic support for ring buffers of any type, as opposed to the os/lib/ringbuf module which is only for byte arrays. Simply returns index in the ringbuf rather than actual elements. The ringbuf size must be power of two. Like the original ringbuf, this module implements atomic put and get.

Author
Simon Duquennoy simon.nosp@m.duq@.nosp@m.sics..nosp@m.se based on Contiki's os/lib/ringbuf library by Adam Dunkels

Definition in file ringbufindex.c.

Function Documentation

◆ ringbufindex_elements()

int ringbufindex_elements ( const struct ringbufindex *  r)

Return the number of elements currently in the ring buffer.

Parameters
rPinter to ringbufindex
Returns
The number of elements in the ring buffer

Definition at line 134 of file ringbufindex.c.

Referenced by ringbufindex_empty().

◆ ringbufindex_empty()

int ringbufindex_empty ( const struct ringbufindex *  r)

Is the ring buffer empty?

Return values
0Not empty
1Empty

Definition at line 146 of file ringbufindex.c.

References ringbufindex_elements().

◆ ringbufindex_full()

int ringbufindex_full ( const struct ringbufindex *  r)

Is the ring buffer full?

Return values
0Not full
1Full

Definition at line 140 of file ringbufindex.c.

◆ ringbufindex_get()

int ringbufindex_get ( struct ringbufindex *  r)

Remove the first element and return its index.

Parameters
rPinter to ringbufindex
Return values
>=0 The index of the first element
-1No element in the ring buffer

Definition at line 90 of file ringbufindex.c.

◆ ringbufindex_init()

void ringbufindex_init ( struct ringbufindex *  r,
uint8_t  size 
)

Initialize a ring buffer.

The size must be a power of two

Parameters
rPointer to ringbufindex
sizeSize of ring buffer

Definition at line 50 of file ringbufindex.c.

◆ ringbufindex_peek_get()

int ringbufindex_peek_get ( const struct ringbufindex *  r)

Return the index of the first element which will be removed if calling ringbufindex_get.

Parameters
rPinter to ringbufindex
Return values
>=0 The index of the first element
-1No element in the ring buffer

Definition at line 115 of file ringbufindex.c.

◆ ringbufindex_peek_put()

int ringbufindex_peek_put ( const struct ringbufindex *  r)

Check if there is space to put an element.

Parameters
rPinter to ringbufindex
Return values
>=0 The index where the next element is to be added.
-1Failure; the ring buffer is full

Definition at line 78 of file ringbufindex.c.

◆ ringbufindex_put()

int ringbufindex_put ( struct ringbufindex *  r)

Put one element to the ring buffer.

Parameters
rPointer to ringbufindex
Return values
0Failure; the ring buffer is full
1Success; an element is added

Definition at line 58 of file ringbufindex.c.

◆ ringbufindex_size()

int ringbufindex_size ( const struct ringbufindex *  r)

Return the ring buffer size.

Parameters
rPinter to ringbufindex
Returns
The size of the ring buffer

Definition at line 128 of file ringbufindex.c.