]> git.proxmox.com Git - mirror_ovs.git/blame - lib/ovs-atomic-c++.h
ovsdb-idl: Fix iteration over tracked rows with no actual data.
[mirror_ovs.git] / lib / ovs-atomic-c++.h
CommitLineData
adabd65d
BP
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
11using std::atomic_init;
12
13using std::memory_order_relaxed;
14using std::memory_order_consume;
15using std::memory_order_acquire;
16using std::memory_order_release;
17using std::memory_order_acq_rel;
18using std::memory_order_seq_cst;
19
20using std::atomic_thread_fence;
21using std::atomic_signal_fence;
22using std::atomic_is_lock_free;
23
24using std::atomic_store;
25using std::atomic_store_explicit;
26
27using std::atomic_compare_exchange_strong;
28using std::atomic_compare_exchange_strong_explicit;
29using std::atomic_compare_exchange_weak;
30using 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) \
35736cff 50 (*(ORIG) = (*(RMW)).fetch_add(ARG, ORDER), (void) 0)
adabd65d 51#define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
35736cff 52 (*(ORIG) = (*(RMW)).fetch_sub(ARG, ORDER), (void) 0)
adabd65d 53#define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
35736cff 54 (*(ORIG) = (*(RMW)).fetch_or(ARG, ORDER), (void) 0)
adabd65d 55#define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
35736cff 56 (*(ORIG) = (*(RMW)).fetch_xor(ARG, ORDER), (void) 0)
adabd65d 57#define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
35736cff 58 (*(ORIG) = (*(RMW)).fetch_and(ARG, ORDER), (void) 0)
adabd65d
BP
59
60using std::atomic_flag;
61using std::atomic_flag_test_and_set_explicit;
62using std::atomic_flag_test_and_set;
63using std::atomic_flag_clear_explicit;
64using std::atomic_flag_clear;