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

Non-thread-safe fifo (FIFO) implementation. More...

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

Go to the source code of this file.

Data Structures

struct  fr_fifo_s
 

Functions

static int _fifo_free (fr_fifo_t *fi)
 Free a fifo and optionally, any data still enqueued. More...
 
fr_fifo_t_fr_fifo_create (TALLOC_CTX *ctx, char const *type, int max, fr_fifo_free_t free_node)
 Create a fifo queue. More...
 
unsigned int fr_fifo_num_elements (fr_fifo_t *fi)
 Return the number of elements in the fifo queue. More...
 
void * fr_fifo_peek (fr_fifo_t *fi)
 Examine the next element that would be popped. More...
 
void * fr_fifo_pop (fr_fifo_t *fi)
 Pop data off of the fifo. More...
 
int fr_fifo_push (fr_fifo_t *fi, void *data)
 Push data onto the fifo. More...
 

Detailed Description

Non-thread-safe fifo (FIFO) implementation.

Definition in file fifo.c.


Data Structure Documentation

◆ fr_fifo_s

struct fr_fifo_s

Definition at line 30 of file fifo.c.

Data Fields
void * data[1]
unsigned int first
fr_fifo_free_t free_node Function to call to free nodes when the fifo is freed.
unsigned int last Head and tail indexes for the fifo.
unsigned int max How many elements were created in the fifo.
unsigned int num How many elements exist in the fifo.
char const * type Type of elements.

Function Documentation

◆ _fifo_free()

static int _fifo_free ( fr_fifo_t fi)
static

Free a fifo and optionally, any data still enqueued.

Parameters
[in]fito free.
Returns
0

Definition at line 46 of file fifo.c.

+ Here is the caller graph for this function:

◆ _fr_fifo_create()

fr_fifo_t* _fr_fifo_create ( TALLOC_CTX *  ctx,
char const *  type,
int  max,
fr_fifo_free_t  free_node 
)

Create a fifo queue.

The first element enqueued will be the first to be dequeued.

Note
The created fifo does not provide any thread synchronisation functionality such as mutexes. If multiple threads are enqueueing and dequeueing data the callers must synchronise their access.
Parameters
[in]ctxto allocate fifo array in.
[in]typeTalloc type of elements (may be NULL).
[in]maxThe maximum number of elements allowed.
[in]free_nodeFunction to use to free node data if the fifo is freed.
Returns
  • A new fifo queue.
  • NULL on error.

Definition at line 85 of file fifo.c.

+ Here is the call graph for this function:

◆ fr_fifo_num_elements()

unsigned int fr_fifo_num_elements ( fr_fifo_t fi)

Return the number of elements in the fifo queue.

Parameters
[in]fiFIFO to count elements in.
Returns
the number of elements

Definition at line 170 of file fifo.c.

+ Here is the caller graph for this function:

◆ fr_fifo_peek()

void* fr_fifo_peek ( fr_fifo_t fi)

Examine the next element that would be popped.

Parameters
[in]fiFIFO to peek at.
Returns
  • The data at the head of the queue
  • NULL if the queue is empty.

Definition at line 158 of file fifo.c.

+ Here is the caller graph for this function:

◆ fr_fifo_pop()

void* fr_fifo_pop ( fr_fifo_t fi)

Pop data off of the fifo.

Parameters
[in]fiFIFO to pop data from.
Returns
  • The data popped.
  • NULL if the queue is empty.

Definition at line 135 of file fifo.c.

+ Here is the caller graph for this function:

◆ fr_fifo_push()

int fr_fifo_push ( fr_fifo_t fi,
void *  data 
)

Push data onto the fifo.

Parameters
[in]fiFIFO to push data onto.
[in]datato push.
Returns
  • 0 on success.
  • -1 on error.

Definition at line 111 of file fifo.c.

+ Here is the caller graph for this function: