Implementation of a circular buffer with fixed element size.
More...
#include <freeradius-devel/util/fring.h>
#include <pthread.h>
Go to the source code of this file.
Implementation of a circular buffer with fixed element size.
This offers similar functionality to ring_buffer.c, but uses a fixed element size, and expects all elements to be talloced.
- Copyright
- 2013 The FreeRADIUS server project
-
2013 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.c.
◆ fr_fring_buffer
Standard thread safe circular buffer.
Definition at line 36 of file fring.c.
Data Fields |
void ** |
data |
Ring buffer data. |
void const * |
end |
End of allocated memory. |
uint32_t |
in |
Write index. |
bool |
lock |
Perform thread synchronisation. |
pthread_mutex_t |
mutex |
Thread synchronisation mutex. |
uint32_t |
out |
Read index. |
uint32_t |
size |
|
◆ _fring_free()
Destroy mutex associated with ring buffer.
- Parameters
-
- Returns
- 0
Definition at line 55 of file fring.c.
◆ 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.