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
25 memory_order_relaxed = __ATOMIC_RELAXED,
26 memory_order_consume = __ATOMIC_CONSUME,
27 memory_order_acquire = __ATOMIC_ACQUIRE,
28 memory_order_release = __ATOMIC_RELEASE,
29 memory_order_acq_rel = __ATOMIC_ACQ_REL,
30 memory_order_seq_cst = __ATOMIC_SEQ_CST
33 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
34 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
35 #define atomic_destroy(OBJECT) ((void) (OBJECT))
37 #define atomic_thread_fence __atomic_thread_fence
38 #define atomic_signal_fence __atomic_signal_fence
39 #define atomic_is_lock_free __atomic_is_lock_free
41 #define atomic_store(DST, SRC) \
42 atomic_store_explicit(DST, SRC, memory_order_seq_cst)
43 #define atomic_store_explicit __atomic_store_n
45 #define atomic_read(SRC, DST) \
46 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
47 #define atomic_read_explicit(SRC, DST, ORDER) \
48 (*(DST) = __atomic_load_n(SRC, ORDER), \
51 #define atomic_add(RMW, OPERAND, ORIG) \
52 atomic_add_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
53 #define atomic_sub(RMW, OPERAND, ORIG) \
54 atomic_sub_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
55 #define atomic_or(RMW, OPERAND, ORIG) \
56 atomic_or_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
57 #define atomic_xor(RMW, OPERAND, ORIG) \
58 atomic_xor_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
59 #define atomic_and(RMW, OPERAND, ORIG) \
60 atomic_and_explicit(RMW, OPERAND, ORIG, memory_order_seq_cst)
62 #define atomic_add_explicit(RMW, OPERAND, ORIG, ORDER) \
63 (*(ORIG) = __atomic_fetch_add(RMW, OPERAND, ORDER), (void) 0)
64 #define atomic_sub_explicit(RMW, OPERAND, ORIG, ORDER) \
65 (*(ORIG) = __atomic_fetch_sub(RMW, OPERAND, ORDER), (void) 0)
66 #define atomic_or_explicit(RMW, OPERAND, ORIG, ORDER) \
67 (*(ORIG) = __atomic_fetch_or(RMW, OPERAND, ORDER), (void) 0)
68 #define atomic_xor_explicit(RMW, OPERAND, ORIG, ORDER) \
69 (*(ORIG) = __atomic_fetch_xor(RMW, OPERAND, ORDER), (void) 0)
70 #define atomic_and_explicit(RMW, OPERAND, ORIG, ORDER) \
71 (*(ORIG) = __atomic_fetch_and(RMW, OPERAND, ORDER), (void) 0)
73 #include "ovs-atomic-flag-gcc4.7+.h"