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)
25 #include "ovs-atomic-types.h"
27 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
29 #define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
30 #define atomic_destroy(OBJECT) ((void) (OBJECT))
32 /* Clang hard-codes these exact values internally but does not appear to
33 * export any names for them. */
35 memory_order_relaxed = 0,
36 memory_order_consume = 1,
37 memory_order_acquire = 2,
38 memory_order_release = 3,
39 memory_order_acq_rel = 4,
40 memory_order_seq_cst = 5
43 #define atomic_thread_fence(ORDER) __c11_atomic_thread_fence(ORDER)
44 #define atomic_signal_fence(ORDER) __c11_atomic_signal_fence(ORDER)
46 #define atomic_store(DST, SRC) \
47 atomic_store_explicit(DST, SRC, memory_order_seq_cst)
48 #define atomic_store_explicit(DST, SRC, ORDER) \
49 __c11_atomic_store(DST, SRC, ORDER)
52 #define atomic_read(SRC, DST) \
53 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
54 #define atomic_read_explicit(SRC, DST, ORDER) \
55 (*(DST) = __c11_atomic_load(SRC, ORDER), \
58 #define atomic_add(RMW, ARG, ORIG) \
59 atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
60 #define atomic_sub(RMW, ARG, ORIG) \
61 atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
62 #define atomic_or(RMW, ARG, ORIG) \
63 atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
64 #define atomic_xor(RMW, ARG, ORIG) \
65 atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
66 #define atomic_and(RMW, ARG, ORIG) \
67 atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
69 #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
70 (*(ORIG) = __c11_atomic_fetch_add(RMW, ARG, ORDER), (void) 0)
71 #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
72 (*(ORIG) = __c11_atomic_fetch_sub(RMW, ARG, ORDER), (void) 0)
73 #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
74 (*(ORIG) = __c11_atomic_fetch_or(RMW, ARG, ORDER), (void) 0)
75 #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
76 (*(ORIG) = __c11_atomic_fetch_xor(RMW, ARG, ORDER), (void) 0)
77 #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
78 (*(ORIG) = __c11_atomic_fetch_and(RMW, ARG, ORDER), (void) 0)
80 #include "ovs-atomic-flag-gcc4.7+.h"