mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 03:28:31 +00:00
lib: add atomic bitwise OR, AND
* Add support for C11 bitwise OR & AND operations * Add atomic versions of bitfield macros Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
85121506e7
commit
f765d422d1
@ -46,6 +46,8 @@
|
|||||||
#define atomic_exchange_explicit __atomic_exchange_n
|
#define atomic_exchange_explicit __atomic_exchange_n
|
||||||
#define atomic_fetch_add_explicit __atomic_fetch_add
|
#define atomic_fetch_add_explicit __atomic_fetch_add
|
||||||
#define atomic_fetch_sub_explicit __atomic_fetch_sub
|
#define atomic_fetch_sub_explicit __atomic_fetch_sub
|
||||||
|
#define atomic_fetch_and_explicit __atomic_fetch_and
|
||||||
|
#define atomic_fetch_or_explicit __atomic_fetch_or
|
||||||
|
|
||||||
#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, \
|
#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, \
|
||||||
mem2) \
|
mem2) \
|
||||||
@ -135,6 +137,20 @@
|
|||||||
*_expect = rval; \
|
*_expect = rval; \
|
||||||
ret; \
|
ret; \
|
||||||
})
|
})
|
||||||
|
#define atomic_fetch_and_explicit(ptr, val, mem) \
|
||||||
|
({ \
|
||||||
|
__sync_synchronize(); \
|
||||||
|
typeof(*ptr) rval = __sync_fetch_and_and(ptr, val); \
|
||||||
|
__sync_synchronize(); \
|
||||||
|
rval; \
|
||||||
|
})
|
||||||
|
#define atomic_fetch_or_explicit(ptr, val, mem) \
|
||||||
|
({ \
|
||||||
|
__sync_synchronize(); \
|
||||||
|
typeof(*ptr) rval = __sync_fetch_and_or(ptr, val); \
|
||||||
|
__sync_synchronize(); \
|
||||||
|
rval; \
|
||||||
|
})
|
||||||
|
|
||||||
#else /* !HAVE___ATOMIC && !HAVE_STDATOMIC_H */
|
#else /* !HAVE___ATOMIC && !HAVE_STDATOMIC_H */
|
||||||
#error no atomic functions...
|
#error no atomic functions...
|
||||||
|
10
lib/zebra.h
10
lib/zebra.h
@ -481,6 +481,16 @@ typedef enum {
|
|||||||
#define UNSET_FLAG(V,F) (V) &= ~(F)
|
#define UNSET_FLAG(V,F) (V) &= ~(F)
|
||||||
#define RESET_FLAG(V) (V) = 0
|
#define RESET_FLAG(V) (V) = 0
|
||||||
|
|
||||||
|
/* Atomic flag manipulation macros. */
|
||||||
|
#define CHECK_FLAG_ATOMIC(PV, F) \
|
||||||
|
((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
|
||||||
|
#define SET_FLAG_ATOMIC(PV, F) \
|
||||||
|
((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
|
||||||
|
#define UNSET_FLAG_ATOMIC(PV, F) \
|
||||||
|
((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
|
||||||
|
#define RESET_FLAG_ATOMIC(PV) \
|
||||||
|
((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
|
||||||
|
|
||||||
/* Zebra types. Used in Zserv message header. */
|
/* Zebra types. Used in Zserv message header. */
|
||||||
typedef u_int16_t zebra_size_t;
|
typedef u_int16_t zebra_size_t;
|
||||||
typedef u_int16_t zebra_command_t;
|
typedef u_int16_t zebra_command_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user