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

Thread-safe queues. More...

#include <stdint.h>
#include <stdalign.h>
#include <inttypes.h>
#include <freeradius-devel/autoconf.h>
#include <freeradius-devel/io/atomic_queue.h>
#include <freeradius-devel/util/talloc.h>
+ Include dependency graph for atomic_queue.c:

Go to the source code of this file.

Data Structures

struct  fr_atomic_queue_entry_t
 Entry in the queue. More...
 
struct  fr_atomic_queue_s
 Structure to hold the atomic queue. More...
 

Macros

#define CACHE_LINE_SIZE   64
 

Functions

fr_atomic_queue_tfr_atomic_queue_alloc (TALLOC_CTX *ctx, size_t size)
 Create fixed-size atomic queue. More...
 
void fr_atomic_queue_debug (fr_atomic_queue_t *aq, FILE *fp)
 Dump an atomic queue. More...
 
void fr_atomic_queue_free (fr_atomic_queue_t **aq)
 Free an atomic queue if it's not freed by ctx. More...
 
bool fr_atomic_queue_pop (fr_atomic_queue_t *aq, void **p_data)
 Pop a pointer from the atomic queue. More...
 
bool fr_atomic_queue_push (fr_atomic_queue_t *aq, void *data)
 Push a pointer into the atomic queue. More...
 
size_t fr_atomic_queue_size (fr_atomic_queue_t *aq)
 

Detailed Description

Thread-safe queues.

Id
4c9b7eac8aec45848041939320b3ab29e966ff9f

Definition in file atomic_queue.c.


Data Structure Documentation

◆ fr_atomic_queue_entry_t

struct fr_atomic_queue_entry_t

Entry in the queue.

Note
This structure is cache line aligned for modern AMD/Intel CPUs. This is to avoid contention when the producer and consumer are executing on different CPU cores.

Definition at line 44 of file atomic_queue.c.

Data Fields
void * data
atomic_int64_t seq Must be seq then data to ensure seq is 64bit aligned for 32bit address spaces.

◆ fr_atomic_queue_s

struct fr_atomic_queue_s

Structure to hold the atomic queue.

Definition at line 54 of file atomic_queue.c.

+ Collaboration diagram for fr_atomic_queue_s:
Data Fields
void * chunk To pass to free. The non-aligned address.
fr_atomic_queue_entry_t entry[] The entry array, also aligned to ensure it's not in the same cache line as tail and size.
atomic_int64_t head Head, aligned bytes to ensure it's in a different cache line to tail to reduce memory contention.
size_t size
atomic_int64_t tail

Macro Definition Documentation

◆ CACHE_LINE_SIZE

#define CACHE_LINE_SIZE   64

Definition at line 36 of file atomic_queue.c.

Function Documentation

◆ fr_atomic_queue_alloc()

fr_atomic_queue_t* fr_atomic_queue_alloc ( TALLOC_CTX *  ctx,
size_t  size 
)

Create fixed-size atomic queue.

Note
the queue must be freed explicitly by the ctx being freed, or by using the fr_atomic_queue_free function.
Parameters
[in]ctxThe talloc ctx to allocate the queue in.
[in]sizeThe number of entries in the queue.
Returns
  • NULL on error.
  • fr_atomic_queue_t *, a pointer to the allocated and initialized queue.

Definition at line 80 of file atomic_queue.c.

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

◆ fr_atomic_queue_debug()

void fr_atomic_queue_debug ( fr_atomic_queue_t aq,
FILE *  fp 
)

Dump an atomic queue.

Absolutely NOT thread-safe.

Parameters
[in]aqThe atomic queue to debug.
[in]fpwhere the debugging information will be printed.

Definition at line 301 of file atomic_queue.c.

+ Here is the caller graph for this function:

◆ fr_atomic_queue_free()

void fr_atomic_queue_free ( fr_atomic_queue_t **  aq)

Free an atomic queue if it's not freed by ctx.

This function is needed because the atomic queue memory must be cache line aligned.

Definition at line 132 of file atomic_queue.c.

+ Here is the call graph for this function:

◆ fr_atomic_queue_pop()

bool fr_atomic_queue_pop ( fr_atomic_queue_t aq,
void **  p_data 
)

Pop a pointer from the atomic queue.

Parameters
[in]aqthe atomic queue to retrieve data from.
[out]p_datawhere to write the data.
Returns
  • true on successful pop
  • false on queue empty

Definition at line 215 of file atomic_queue.c.

+ Here is the caller graph for this function:

◆ fr_atomic_queue_push()

bool fr_atomic_queue_push ( fr_atomic_queue_t aq,
void *  data 
)

Push a pointer into the atomic queue.

Parameters
[in]aqThe atomic queue to add data to.
[in]datato push.
Returns
  • true on successful push
  • false on queue full

Definition at line 148 of file atomic_queue.c.

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

◆ fr_atomic_queue_size()

size_t fr_atomic_queue_size ( fr_atomic_queue_t aq)

Definition at line 265 of file atomic_queue.c.

+ Here is the caller graph for this function: