Contiki-NG
Loading...
Searching...
No Matches
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.
 
int ringbufindex_put (struct ringbufindex *r)
 Put one element to the ring buffer.
 
int ringbufindex_peek_put (const struct ringbufindex *r)
 Check if there is space to put an element.
 
int ringbufindex_get (struct ringbufindex *r)
 Remove the first element and return its index.
 
int ringbufindex_peek_get (const struct ringbufindex *r)
 Return the index of the first element which will be removed if calling ringbufindex_get.
 

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_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.

Referenced by tsch_queue_remove_packet_from_queue().

◆ 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.

Referenced by tsch_queue_add_nbr().

◆ 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.

Referenced by tsch_queue_get_packet_for_nbr().

◆ 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.

Referenced by tsch_queue_add_packet().

◆ 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.

Referenced by tsch_queue_add_packet().