The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Typedefs | Functions
ring_buffer.h File Reference

Ring buffers. More...

#include <freeradius-devel/util/talloc.h>
#include <stdbool.h>
#include <stdint.h>
+ Include dependency graph for ring_buffer.h:

Go to the source code of this file.

Typedefs

typedef struct fr_ring_buffer_s fr_ring_buffer_t
 

Functions

uint8_tfr_ring_buffer_alloc (fr_ring_buffer_t *rb, size_t size)
 Mark data as allocated. More...
 
int fr_ring_buffer_close (fr_ring_buffer_t *rb)
 Close a ring buffer so that no further allocations can take place. More...
 
fr_ring_buffer_tfr_ring_buffer_create (TALLOC_CTX *ctx, size_t size)
 Create a ring buffer. More...
 
void fr_ring_buffer_debug (fr_ring_buffer_t *rb, FILE *fp)
 Print debug information about the ring buffer. More...
 
int fr_ring_buffer_free (fr_ring_buffer_t *rb, size_t size)
 Mark data as free,. More...
 
uint8_tfr_ring_buffer_reserve (fr_ring_buffer_t *rb, size_t size)
 Reserve room in the ring buffer. More...
 
size_t fr_ring_buffer_size (fr_ring_buffer_t *rb)
 Get the size of the ring buffer. More...
 
int fr_ring_buffer_start (fr_ring_buffer_t *dst, uint8_t **p_start, size_t *p_size)
 Get a pointer to the data at the start of the ring buffer. More...
 
size_t fr_ring_buffer_used (fr_ring_buffer_t *rb)
 Get the amount of data used in a ring buffer. More...
 

Detailed Description

Ring buffers.

Id
d8f3088307a19dd06a1395d94256ebc8330c2593

Definition in file ring_buffer.h.

Typedef Documentation

◆ fr_ring_buffer_t

Definition at line 1 of file ring_buffer.h.

Function Documentation

◆ fr_ring_buffer_alloc()

uint8_t* fr_ring_buffer_alloc ( fr_ring_buffer_t rb,
size_t  size 
)

Mark data as allocated.

The size does not need to be a power of two. The application is responsible for doing cache-line alignment, if required.

The application does NOT need to call fr_ring_buffer_reserve() before calling this function.

If the allocation fails, the application should create a new ring buffer, and start allocating data there.

Parameters
[in]rba ring buffer
[in]sizeto mark as "used" at the tail end of the buffer.
Returns
  • NULL on error. Which can only be "ring buffer is full".
  • pointer to data on success

Definition at line 196 of file ring_buffer.c.

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

◆ fr_ring_buffer_close()

int fr_ring_buffer_close ( fr_ring_buffer_t rb)

Close a ring buffer so that no further allocations can take place.

Once the ring buffer is empty, it will be automatically freed. It's called "close" and not "delete", because the ring buffer will still be active until all data has been removed.

If you don't care about the data in the ring buffer, you can just call talloc_free() on it.

Parameters
[in]rba ring buffer
Returns
  • <0 on error.
  • 0 on success

Definition at line 407 of file ring_buffer.c.

◆ fr_ring_buffer_create()

fr_ring_buffer_t* fr_ring_buffer_create ( TALLOC_CTX *  ctx,
size_t  size 
)

Create a ring buffer.

The size provided will be rounded up to the next highest power of 2, if it's not already a power of 2.

The ring buffer manages how much room is reserved (i.e. available to write to), and used. The application is responsible for tracking the start of the reservation, and it's write offset within that reservation.

Parameters
[in]ctxa talloc context
[in]sizeof the raw ring buffer array to allocate.
Returns
  • A new ring buffer on success.
  • NULL on failure.

Definition at line 64 of file ring_buffer.c.

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

◆ fr_ring_buffer_debug()

void fr_ring_buffer_debug ( fr_ring_buffer_t rb,
FILE *  fp 
)

Print debug information about the ring buffer.

Parameters
[in]rbthe ring buffer
[in]fpthe FILE where the messages are printed.

Definition at line 485 of file ring_buffer.c.

◆ fr_ring_buffer_free()

int fr_ring_buffer_free ( fr_ring_buffer_t rb,
size_t  size_to_free 
)

Mark data as free,.

The size does not need to be a power of two. The application is responsible for doing cache alignment, if required. The application is responsible for tracking sizes of packets in the ring buffer.

If "unused" bytes are more than what's in the buffer, the used bytes are reset to zero.

Parameters
[in]rba ring buffer
[in]size_to_freebytes to mark as "unused" in the buffer.
Returns
  • <0 on error. Which can only be "ring buffer is full".
  • 0 on success

Definition at line 304 of file ring_buffer.c.

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

◆ fr_ring_buffer_reserve()

uint8_t* fr_ring_buffer_reserve ( fr_ring_buffer_t rb,
size_t  size 
)

Reserve room in the ring buffer.

The size does not need to be a power of two. The application is responsible for doing cache alignment, if required.

If the reservation fails, the application should create a new ring buffer, and start reserving data there.

Parameters
[in]rba ring buffer
[in]sizeto see if we can reserve
Returns
  • NULL on error. Which can only be "ring buffer is full".
  • pointer to data on success

Definition at line 119 of file ring_buffer.c.

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

◆ fr_ring_buffer_size()

size_t fr_ring_buffer_size ( fr_ring_buffer_t rb)

Get the size of the ring buffer.

Parameters
[in]rba ring buffer
Returns
size of the ring buffer.
  • <0 on error.
  • 0 on success

Definition at line 423 of file ring_buffer.c.

+ Here is the caller graph for this function:

◆ fr_ring_buffer_start()

int fr_ring_buffer_start ( fr_ring_buffer_t rb,
uint8_t **  p_start,
size_t p_size 
)

Get a pointer to the data at the start of the ring buffer.

Parameters
[in]rba ring buffer
[out]p_startpointer to data at the start of the ring buffer
[in]p_sizesize of the allocated block at the start of the ring buffer.
Returns
size of the used data in the ring buffer.
  • <0 on error.
  • 0 on success

Definition at line 464 of file ring_buffer.c.

+ Here is the caller graph for this function:

◆ fr_ring_buffer_used()

size_t fr_ring_buffer_used ( fr_ring_buffer_t rb)

Get the amount of data used in a ring buffer.

Parameters
[in]rba ring buffer
Returns
size of the used data in the ring buffer.
  • <0 on error.
  • 0 on success

Definition at line 437 of file ring_buffer.c.

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