Exported symbols from ringbuffer.c.
More...
Exported symbols from ringbuffer.c.
◆ ringbuffer_new()
struct ringbuffer* ringbuffer_new |
( |
unsigned |
size | ) |
|
Initialize a new ringbuffer.
- Parameters
-
size | The number of entries the ringbuffer holds. |
This function initializes a circular ring buffer which can hold up to size entries of arbitrary type. If performance is an issue, size should be a power of two to make the underlying modulo operations cheap. Arbitrary many ringbuffers may be initialized via this function. Each ringbuffer is identified by a 'cookie'.
- Returns
- A 'cookie' which identifies the ringbuffer just created and which must be passed to ringbuffer_add() and ringbuffer_get().
References zalloc().
◆ ringbuffer_add()
void* ringbuffer_add |
( |
struct ringbuffer * |
rb, |
|
|
void * |
data |
|
) |
| |
Add one entry to a ringbuffer.
- Parameters
-
rb | The ringbuffer identifier. |
data | The data to be inserted. |
Insert data into the ringbuffer associated with cookie. As soon as the ringbuffer fills up, its oldest entry is disregarded and replaced by data.
- Returns
- The old data pointer which is going to be disregarded, or NULL if the ringbuffer is not yet full.
◆ ringbuffer_get()
void* ringbuffer_get |
( |
struct ringbuffer * |
rb, |
|
|
int |
num |
|
) |
| |
Get one entry from a ringbuffer.
- Parameters
-
rb | The ringbuffer identifier. |
num | The number of the entry. |
- Returns
- A pointer to data previously added, or NULL if entry number num is not available. num counts backwards from zero, i.e. ringbuffer_get_entry(0) gets the entry which was added most recently.
◆ ringbuffer_filled()
unsigned ringbuffer_filled |
( |
struct ringbuffer * |
rb | ) |
|
Get the number of entries in the ring buffer.
- Parameters
-
rb | The ringbuffer identifier |
- Returns
- This function always succeeds. It returns a number less than the size of the ring buffer.