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

Thread-safe queues. More...

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

Go to the source code of this file.

Macros

#define aquire(_var)   atomic_load_explicit(&_var, memory_order_acquire)
 
#define atomic_int64_t   _Atomic(int64_t)
 
#define atomic_uint32_t   _Atomic(uint32_t)
 
#define atomic_uint64_t   _Atomic(uint64_t)
 
#define cas_decr(_store, _var)   atomic_compare_exchange_strong_explicit(&_store, &_var, _var - 1, memory_order_release, memory_order_relaxed)
 
#define cas_incr(_store, _var)   atomic_compare_exchange_strong_explicit(&_store, &_var, _var + 1, memory_order_release, memory_order_relaxed)
 
#define load(_var)   atomic_load_explicit(&_var, memory_order_relaxed)
 
#define store(_store, _var)   atomic_store_explicit(&_store, _var, memory_order_release)
 

Typedefs

typedef struct fr_atomic_queue_s fr_atomic_queue_t
 

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
fb096dd9a62ff019c2dd770f854ec76775c3c2da

Definition in file atomic_queue.h.

Macro Definition Documentation

◆ aquire

#define aquire (   _var)    atomic_load_explicit(&_var, memory_order_acquire)

Definition at line 47 of file atomic_queue.h.

◆ atomic_int64_t

#define atomic_int64_t   _Atomic(int64_t)

Definition at line 40 of file atomic_queue.h.

◆ atomic_uint32_t

#define atomic_uint32_t   _Atomic(uint32_t)

Definition at line 41 of file atomic_queue.h.

◆ atomic_uint64_t

#define atomic_uint64_t   _Atomic(uint64_t)

Definition at line 42 of file atomic_queue.h.

◆ cas_decr

#define cas_decr (   _store,
  _var 
)    atomic_compare_exchange_strong_explicit(&_store, &_var, _var - 1, memory_order_release, memory_order_relaxed)

Definition at line 45 of file atomic_queue.h.

◆ cas_incr

#define cas_incr (   _store,
  _var 
)    atomic_compare_exchange_strong_explicit(&_store, &_var, _var + 1, memory_order_release, memory_order_relaxed)

Definition at line 44 of file atomic_queue.h.

◆ load

#define load (   _var)    atomic_load_explicit(&_var, memory_order_relaxed)

Definition at line 46 of file atomic_queue.h.

◆ store

#define store (   _store,
  _var 
)    atomic_store_explicit(&_store, _var, memory_order_release)

Definition at line 48 of file atomic_queue.h.

Typedef Documentation

◆ fr_atomic_queue_t

Definition at line 1 of file atomic_queue.h.

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: