The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Functions
fring.c File Reference

Implementation of a circular buffer with fixed element size. More...

#include <freeradius-devel/util/fring.h>
#include <pthread.h>
+ Include dependency graph for fring.c:

Go to the source code of this file.

Data Structures

struct  fr_fring_buffer
 Standard thread safe circular buffer. More...
 

Functions

static int _fring_free (fr_fring_t *fring)
 Destroy mutex associated with ring buffer. More...
 
fr_fring_tfr_fring_alloc (TALLOC_CTX *ctx, uint32_t size, bool lock)
 Initialise a ring buffer with fixed element size. More...
 
int fr_fring_insert (fr_fring_t *fring, void *in)
 Insert a new item into the circular buffer if the buffer is not full. More...
 
void * fr_fring_next (fr_fring_t *fring)
 Remove an item from the buffer. More...
 
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. More...
 

Detailed Description

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.

Definition in file fring.c.


Data Structure Documentation

◆ fr_fring_buffer

struct fr_fring_buffer

Standard thread safe circular buffer.

Definition at line 36 of file fring.c.

+ Collaboration diagram for fr_fring_buffer:
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

Function Documentation

◆ _fring_free()

static int _fring_free ( fr_fring_t fring)
static

Destroy mutex associated with ring buffer.

Parameters
[in]fringbeing freed.
Returns
0

Definition at line 55 of file fring.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_fring_alloc()

fr_fring_t* fr_fring_alloc ( TALLOC_CTX *  ctx,
uint32_t  size,
bool  lock 
)

Initialise a ring buffer with fixed element size.

Parameters
[in]ctxto allocate the buffer in.
[in]sizeof buffer to allocate.
[in]lockIf true, insert and next operations will lock the buffer.
Returns
  • New fring.
  • NULL on error.

Definition at line 78 of file fring.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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]fringto insert item into.
[in]initem 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.

+ Here is the call graph for this function:

◆ fr_fring_next()

void* fr_fring_next ( fr_fring_t fring)

Remove an item from the buffer.

Parameters
[in]fringto 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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]fringto insert item into
[in]initem 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: