Simple ring buffer with fixed element sizes.
More...
#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/talloc.h>
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Simple ring buffer with fixed element sizes.
- Copyright
- 2015-2017 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
Definition in file fring.h.
◆ fr_fring_t
◆ fr_fring_alloc()
Initialise a ring buffer with fixed element size.
- Parameters
-
[in] | ctx | to allocate the buffer in. |
[in] | size | of buffer to allocate. |
[in] | lock | If true, insert and next operations will lock the buffer. |
- Returns
- New fring.
- NULL on error.
Definition at line 78 of file fring.c.
◆ fr_fring_insert()
int fr_fring_insert |
( |
fr_fring_t * |
fring, |
|
|
void * |
in |
|
) |
| |
Insert a new item into the circular buffer if the buffer is not full.
- Parameters
-
[in] | fring | to insert item into. |
[in] | in | item to insert. |
- Returns
- 0 if we inserted the item.
- -1 if there's no more space in the buffer to insert items
Definition at line 149 of file fring.c.
◆ fr_fring_next()
Remove an item from the buffer.
- Parameters
-
[in] | fring | to drain data from. |
- Returns
- NULL if no dataents in the buffer.
- An dataent from the buffer reparented to ctx.
Definition at line 177 of file fring.c.
◆ fr_fring_overwrite()
int fr_fring_overwrite |
( |
fr_fring_t * |
fring, |
|
|
void * |
in |
|
) |
| |
Insert a new item into the circular buffer, freeing the tail if we hit it.
- Parameters
-
[in] | fring | to insert item into |
[in] | in | item to insert (must have been allocated with talloc). |
- Returns
- 0 if we inserted the item without freeing existing items.
- 1 if we inserted the item, but needed to free an existing item.
Definition at line 120 of file fring.c.