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 GCC 4.7 and later. */
18 #ifndef IN_OVS_ATOMIC_H
19 #error "This header should only be included indirectly via ovs-atomic.h."
22 #define ATOMIC(TYPE) TYPE
23 #include "ovs-atomic-types.h"
26 memory_order_relaxed = __ATOMIC_RELAXED,
27 memory_order_consume = __ATOMIC_CONSUME,
28 memory_order_acquire = __ATOMIC_ACQUIRE,
29 memory_order_release = __ATOMIC_RELEASE,
30 memory_order_acq_rel = __ATOMIC_ACQ_REL,
31 memory_order_seq_cst = __ATOMIC_SEQ_CST
34 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
35 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
36 #define atomic_destroy(OBJECT) ((void) (OBJECT))
38 #define atomic_thread_fence __atomic_thread_fence
39 #define atomic_signal_fence __atomic_signal_fence
40 #define atomic_is_lock_free __atomic_is_lock_free
42 #define atomic_store(DST, SRC) \
43 atomic_store_explicit(DST, SRC, memory_order_seq_cst)
44 #define atomic_store_explicit __atomic_store_n
46 #define atomic_read(SRC, DST) \
47 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
48 #define atomic_read_explicit(SRC, DST, ORDER) \
49 (*(DST) = __atomic_load_n(SRC, ORDER), \
52 #define atomic_add(RMW, OPERAND, ORIG) \
53 atomic_add_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
54 #define atomic_sub(RMW, OPERAND, ORIG) \
55 atomic_sub_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
56 #define atomic_or(RMW, OPERAND, ORIG) \
57 atomic_or_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
58 #define atomic_xor(RMW, OPERAND, ORIG) \
59 atomic_xor_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
60 #define atomic_and(RMW, OPERAND, ORIG) \
61 atomic_and_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
63 #define atomic_add_explicit(RMW, OPERAND, ORIG, ORDER) \
64 (*(ORIG) = __atomic_fetch_add(RMW, OPERAND, ORDER), (void) 0)
65 #define atomic_sub_explicit(RMW, OPERAND, ORIG, ORDER) \
66 (*(ORIG) = __atomic_fetch_sub(RMW, OPERAND, ORDER), (void) 0)
67 #define atomic_or_explicit(RMW, OPERAND, ORIG, ORDER) \
68 (*(ORIG) = __atomic_fetch_or(RMW, OPERAND, ORDER), (void) 0)
69 #define atomic_xor_explicit(RMW, OPERAND, ORIG, ORDER) \
70 (*(ORIG) = __atomic_fetch_xor(RMW, OPERAND, ORDER), (void) 0)
71 #define atomic_and_explicit(RMW, OPERAND, ORIG, ORDER) \
72 (*(ORIG) = __atomic_fetch_and(RMW, OPERAND, ORDER), (void) 0)
74 #include "ovs-atomic-flag-gcc4.7+.h"