paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Functions
ringbuffer.h File Reference

Detailed Description

Exported symbols from ringbuffer.c.

Functions

struct ringbuffer * ringbuffer_new (unsigned size)
 
void * ringbuffer_add (struct ringbuffer *rb, void *data)
 
void * ringbuffer_get (struct ringbuffer *rb, int num)
 
unsigned ringbuffer_filled (struct ringbuffer *rb)
 
void ringbuffer_flush (struct ringbuffer *rb, void(*free_func)(void *))
 

Function Documentation

◆ ringbuffer_new()

struct ringbuffer* ringbuffer_new ( unsigned  size)

Initialize a new ringbuffer.

Parameters
sizeThe number of entries the ringbuffer holds.

This function initializes a circular buffer which can store up to the given number of entries. The entries can be of arbitrary type. Each ringbuffer is identified by an opaque handle which is returned by this function.

Returns
An opaque handle which identifies the new ringbuffer. Other functions of the ringbuffer API such as to ringbuffer_add() and ringbuffer_get() take a handle as their first argument.

◆ ringbuffer_add()

void* ringbuffer_add ( struct ringbuffer *  rb,
void *  data 
)

Add an entry to a ringbuffer.

Parameters
rbThe handle which identifies the ringbuffer instance.
dataPointer to the data to be inserted.

If the ringbuffer is full, the data pointer of the oldest entry is replaced by the given pointer.

Returns
The data pointer which is was disregarded, or NULL if the ringbuffer was not full yet.

◆ ringbuffer_get()

void* ringbuffer_get ( struct ringbuffer *  rb,
int  num 
)

Get one entry from a ringbuffer.

Parameters
rbThe handle which identifies the ringbuffer instance.
numThe number of the entry.
Returns
A pointer to data previously added, or NULL if there is no entry corresponding to the given number. The number counts entries starting at the newest entry so that ringbuffer_get_entry(rb, 0) gets the entry which was added most recently.

◆ ringbuffer_filled()

unsigned ringbuffer_filled ( struct ringbuffer *  rb)

Get the number of entries in the ringbuffer.

Parameters
rbThe handle which identifies the ringbuffer instance.
Returns
This function always succeeds and returns a number between zero and one less than the size of the ringbuffer, inclusively.

◆ ringbuffer_flush()

void ringbuffer_flush ( struct ringbuffer *  rb,
void(*)(void *)  free_func 
)

Remove all entries from a ringbuffer.

Parameters
rbThe handle which identifies the ringbuffer instance.
free_funcCalled on each existing entry.