]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ovs-atomic-clang.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / ovs-atomic-clang.h
1 /*
2 * Copyright (c) 2013, 2014 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* This header implements atomic operation primitives on Clang. */
18 #ifndef IN_OVS_ATOMIC_H
19 #error "This header should only be included indirectly via ovs-atomic.h."
20 #endif
21
22 #define OVS_ATOMIC_CLANG_IMPL 1
23
24 #define ATOMIC(TYPE) _Atomic(TYPE)
25
26 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
27
28 #define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
29
30 /* Clang hard-codes these exact values internally but does not appear to
31 * export any names for them. */
32 typedef enum {
33 memory_order_relaxed = 0,
34 memory_order_consume = 1,
35 memory_order_acquire = 2,
36 memory_order_release = 3,
37 memory_order_acq_rel = 4,
38 memory_order_seq_cst = 5
39 } memory_order;
40
41 #define atomic_thread_fence(ORDER) __c11_atomic_thread_fence(ORDER)
42 #define atomic_signal_fence(ORDER) __c11_atomic_signal_fence(ORDER)
43
44 #define atomic_store(DST, SRC) \
45 atomic_store_explicit(DST, SRC, memory_order_seq_cst)
46 #define atomic_store_explicit(DST, SRC, ORDER) \
47 __c11_atomic_store(DST, SRC, ORDER)
48
49
50 #define atomic_read(SRC, DST) \
51 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
52 #define atomic_read_explicit(SRC, DST, ORDER) \
53 (*(DST) = __c11_atomic_load(SRC, ORDER), \
54 (void) 0)
55
56 #define atomic_compare_exchange_strong(DST, EXP, SRC) \
57 atomic_compare_exchange_strong_explicit(DST, EXP, SRC, \
58 memory_order_seq_cst, \
59 memory_order_seq_cst)
60 #define atomic_compare_exchange_strong_explicit(DST, EXP, SRC, ORD1, ORD2) \
61 __c11_atomic_compare_exchange_strong(DST, EXP, SRC, ORD1, ORD2)
62
63 #define atomic_compare_exchange_weak(DST, EXP, SRC) \
64 atomic_compare_exchange_weak_explicit(DST, EXP, SRC, \
65 memory_order_seq_cst, \
66 memory_order_seq_cst)
67 #define atomic_compare_exchange_weak_explicit(DST, EXP, SRC, ORD1, ORD2) \
68 __c11_atomic_compare_exchange_weak(DST, EXP, SRC, ORD1, ORD2)
69
70 #define atomic_add(RMW, ARG, ORIG) \
71 atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
72 #define atomic_sub(RMW, ARG, ORIG) \
73 atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
74 #define atomic_or(RMW, ARG, ORIG) \
75 atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
76 #define atomic_xor(RMW, ARG, ORIG) \
77 atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
78 #define atomic_and(RMW, ARG, ORIG) \
79 atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
80
81 #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
82 (*(ORIG) = __c11_atomic_fetch_add(RMW, ARG, ORDER), (void) 0)
83 #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
84 (*(ORIG) = __c11_atomic_fetch_sub(RMW, ARG, ORDER), (void) 0)
85 #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
86 (*(ORIG) = __c11_atomic_fetch_or(RMW, ARG, ORDER), (void) 0)
87 #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
88 (*(ORIG) = __c11_atomic_fetch_xor(RMW, ARG, ORDER), (void) 0)
89 #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
90 (*(ORIG) = __c11_atomic_fetch_and(RMW, ARG, ORDER), (void) 0)
91
92 #include "ovs-atomic-flag-gcc4.7+.h"