Implementation of a ring buffer.
More...
#include <freeradius-devel/libradius.h>
Go to the source code of this file.
Implementation of a ring buffer.
- 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 cbuff.c.
Standard thread safe circular buffer.
Definition at line 39 of file cbuff.c.
Data Fields |
void ** |
elem |
Ring buffer data. |
void const * |
end |
End of allocated memory. |
uint32_t |
in |
Write index. |
bool |
lock |
Perform thread synchronisation. |
uint32_t |
out |
Read index. |
uint32_t |
size |
|
#define PTHREAD_MUTEX_LOCK |
( |
|
_x | ) |
|
#define PTHREAD_MUTEX_UNLOCK |
( |
|
_x | ) |
|
fr_cbuff_t* fr_cbuff_alloc |
( |
TALLOC_CTX * |
ctx, |
|
|
uint32_t |
size, |
|
|
UNUSED bool |
lock |
|
) |
| |
Initialise a new circular buffer.
- Parameters
-
ctx | to allocate the buffer in. |
size | of buffer to allocate. |
lock | If true, insert and next operations will lock the buffer. |
- Returns
- New cbuff.
- NULL on error.
Definition at line 66 of file cbuff.c.
void fr_cbuff_rp_insert |
( |
fr_cbuff_t * |
cbuff, |
|
|
void * |
obj |
|
) |
| |
Insert a new element into the buffer, and steal it from it's original context.
cbuff will steal obj and insert it into it's own context.
- Parameters
-
cbuff | to insert element into |
obj | to insert, must of been allocated with talloc |
Definition at line 108 of file cbuff.c.
void* fr_cbuff_rp_next |
( |
fr_cbuff_t * |
cbuff, |
|
|
TALLOC_CTX * |
ctx |
|
) |
| |
Remove an item from the buffer, and reparent to ctx.
- Parameters
-
cbuff | to remove element from |
ctx | to hang obj off. |
- Returns
- NULL if no elements in the buffer.
- An element from the buffer reparented to ctx.
Definition at line 136 of file cbuff.c.