]>
Commit | Line | Data |
---|---|---|
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 | ||
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) \ | |
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 | |
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; |