2 * Copyright (c) 2013, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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."
22 #define OVS_ATOMIC_CLANG_IMPL 1
24 #define ATOMIC(TYPE) _Atomic(TYPE)
26 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
28 #define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
30 /* Clang hard-codes these exact values internally but does not appear to
31 * export any names for them. */
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
41 #define atomic_thread_fence(ORDER) __c11_atomic_thread_fence(ORDER)
42 #define atomic_signal_fence(ORDER) __c11_atomic_signal_fence(ORDER)
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)
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), \
56 #define atomic_add(RMW, ARG, ORIG) \
57 atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
58 #define atomic_sub(RMW, ARG, ORIG) \
59 atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
60 #define atomic_or(RMW, ARG, ORIG) \
61 atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
62 #define atomic_xor(RMW, ARG, ORIG) \
63 atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
64 #define atomic_and(RMW, ARG, ORIG) \
65 atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
67 #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
68 (*(ORIG) = __c11_atomic_fetch_add(RMW, ARG, ORDER), (void) 0)
69 #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
70 (*(ORIG) = __c11_atomic_fetch_sub(RMW, ARG, ORDER), (void) 0)
71 #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
72 (*(ORIG) = __c11_atomic_fetch_or(RMW, ARG, ORDER), (void) 0)
73 #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
74 (*(ORIG) = __c11_atomic_fetch_xor(RMW, ARG, ORDER), (void) 0)
75 #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
76 (*(ORIG) = __c11_atomic_fetch_and(RMW, ARG, ORDER), (void) 0)
78 #include "ovs-atomic-flag-gcc4.7+.h"