]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ovs-atomic-c++.h
lldp: validate a bit more received LLDP frames
[mirror_ovs.git] / lib / ovs-atomic-c++.h
1 /* This header implements atomic operation primitives on compilers that
2 * have built-in support for ++C11 <atomic> */
3 #ifndef IN_OVS_ATOMIC_H
4 #error "This header should only be included indirectly via ovs-atomic.h."
5 #endif
6
7 #include <atomic>
8
9 #define ATOMIC(TYPE) std::atomic<TYPE>
10
11 using std::atomic_init;
12
13 using std::memory_order_relaxed;
14 using std::memory_order_consume;
15 using std::memory_order_acquire;
16 using std::memory_order_release;
17 using std::memory_order_acq_rel;
18 using std::memory_order_seq_cst;
19
20 using std::atomic_thread_fence;
21 using std::atomic_signal_fence;
22 using std::atomic_is_lock_free;
23
24 using std::atomic_store;
25 using std::atomic_store_explicit;
26
27 using std::atomic_compare_exchange_strong;
28 using std::atomic_compare_exchange_strong_explicit;
29 using std::atomic_compare_exchange_weak;
30 using std::atomic_compare_exchange_weak_explicit;
31
32 #define atomic_read(SRC, DST) \
33 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
34 #define atomic_read_explicit(SRC, DST, ORDER) \
35 (*(DST) = std::atomic_load_explicit(SRC, ORDER), \
36 (void) 0)
37
38 #define atomic_add(RMW, ARG, ORIG) \
39 atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
40 #define atomic_sub(RMW, ARG, ORIG) \
41 atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
42 #define atomic_or(RMW, ARG, ORIG) \
43 atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
44 #define atomic_xor(RMW, ARG, ORIG) \
45 atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
46 #define atomic_and(RMW, ARG, ORIG) \
47 atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
48
49 #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
50 (*(ORIG) = (*(RMW)).fetch_add(ARG, ORDER), (void) 0)
51 #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
52 (*(ORIG) = (*(RMW)).fetch_sub(ARG, ORDER), (void) 0)
53 #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
54 (*(ORIG) = (*(RMW)).fetch_or(ARG, ORDER), (void) 0)
55 #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
56 (*(ORIG) = (*(RMW)).fetch_xor(ARG, ORDER), (void) 0)
57 #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
58 (*(ORIG) = (*(RMW)).fetch_and(ARG, ORDER), (void) 0)
59
60 using std::atomic_flag;
61 using std::atomic_flag_test_and_set_explicit;
62 using std::atomic_flag_test_and_set;
63 using std::atomic_flag_clear_explicit;
64 using std::atomic_flag_clear;