The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
atomic_queue.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: fb096dd9a62ff019c2dd770f854ec76775c3c2da $
20  *
21  * @file io/atomic_queue.h
22  * @brief Thread-safe queues.
23  *
24  * @copyright 2016 Alan DeKok (aland@freeradius.org)
25  */
26 RCSIDH(atomic_queue_h, "$Id: fb096dd9a62ff019c2dd770f854ec76775c3c2da $")
27 
28 #include <stdbool.h>
29 
30 #ifdef HAVE_STDATOMIC_H
31 # include <stdatomic.h>
32 #else
33 # include <freeradius-devel/util/stdatomic.h>
34 #endif
35 #include <freeradius-devel/util/talloc.h>
36 
37 /*
38  * Some macros to make our life easier.
39  */
40 #define atomic_int64_t _Atomic(int64_t)
41 #define atomic_uint32_t _Atomic(uint32_t)
42 #define atomic_uint64_t _Atomic(uint64_t)
43 
44 #define cas_incr(_store, _var) atomic_compare_exchange_strong_explicit(&_store, &_var, _var + 1, memory_order_release, memory_order_relaxed)
45 #define cas_decr(_store, _var) atomic_compare_exchange_strong_explicit(&_store, &_var, _var - 1, memory_order_release, memory_order_relaxed)
46 #define load(_var) atomic_load_explicit(&_var, memory_order_relaxed)
47 #define aquire(_var) atomic_load_explicit(&_var, memory_order_acquire)
48 #define store(_store, _var) atomic_store_explicit(&_store, _var, memory_order_release)
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
55 
56 fr_atomic_queue_t *fr_atomic_queue_alloc(TALLOC_CTX *ctx, size_t size);
59 bool fr_atomic_queue_pop(fr_atomic_queue_t *aq, void **p_data);
61 
62 #ifdef WITH_VERIFY_PTR
63 void fr_atomic_queue_verify(fr_atomic_queue_t *aq);
64 #endif
65 
66 #ifndef NDEBUG
68 #endif
69 
70 
71 #ifdef __cplusplus
72 }
73 #endif
Structure to hold the atomic queue.
Definition: atomic_queue.c:54
bool fr_atomic_queue_pop(fr_atomic_queue_t *aq, void **p_data)
Pop a pointer from the atomic queue.
Definition: atomic_queue.c:215
fr_atomic_queue_t * fr_atomic_queue_alloc(TALLOC_CTX *ctx, size_t size)
Create fixed-size atomic queue.
Definition: atomic_queue.c:80
size_t fr_atomic_queue_size(fr_atomic_queue_t *aq)
Definition: atomic_queue.c:265
bool fr_atomic_queue_push(fr_atomic_queue_t *aq, void *data)
Push a pointer into the atomic queue.
Definition: atomic_queue.c:148
void fr_atomic_queue_free(fr_atomic_queue_t **aq)
Free an atomic queue if it's not freed by ctx.
Definition: atomic_queue.c:132
void fr_atomic_queue_debug(fr_atomic_queue_t *aq, FILE *fp)
Dump an atomic queue.
Definition: atomic_queue.c:301
#define RCSIDH(h, id)
Definition: build.h:445
static fr_atomic_queue_t * aq
Definition: control_test.c:47
static fr_slen_t data
Definition: value.h:1259