From 50b37d4a27d3295a29afca2286f1a5a086142cec Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:49:46 +0200 Subject: Adding upstream version 3.2.1+dfsg. Signed-off-by: Daniel Baumann --- src/include/atomic_queue.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/include/atomic_queue.h (limited to 'src/include/atomic_queue.h') diff --git a/src/include/atomic_queue.h b/src/include/atomic_queue.h new file mode 100644 index 0000000..7d9be91 --- /dev/null +++ b/src/include/atomic_queue.h @@ -0,0 +1,71 @@ +#pragma once +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * $Id$ + * + * @file atomic_queue.h + * @brief Thread-safe queues. + * + * @copyright 2016 Alan DeKok + */ +RCSIDH(atomic_queue_h, "$Id$") + +#ifdef HAVE_WDOCUMENTATION +DIAG_OFF(documentation) +#endif +#include +#ifdef HAVE_WDOCUMENTATION +DIAG_ON(documentation) +#endif +#include + +#ifdef HAVE_STDATOMIC_H +# include +#else +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Some macros to make our life easier. + */ +#define atomic_uint32_t _Atomic(uint32_t) + +#define cas_incr(_store, _var) atomic_compare_exchange_strong_explicit(&_store, &_var, _var + 1, memory_order_release, memory_order_relaxed) +#define cas_decr(_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 aquire(_var) atomic_load_explicit(&_var, memory_order_acquire) +#define store(_store, _var) atomic_store_explicit(&_store, _var, memory_order_release); + +typedef struct fr_atomic_queue_t fr_atomic_queue_t; + +fr_atomic_queue_t *fr_atomic_queue_create(TALLOC_CTX *ctx, int size); +bool fr_atomic_queue_push(fr_atomic_queue_t *aq, void *data); +bool fr_atomic_queue_pop(fr_atomic_queue_t *aq, void **p_data); + +#ifndef NDEBUG +void fr_atomic_queue_debug(fr_atomic_queue_t *aq, FILE *fp); +#endif + + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3