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 compilers that
18 * have built-in support for C11 <stdatomic.h> */
19 #ifndef IN_OVS_ATOMIC_H
20 #error "This header should only be included indirectly via ovs-atomic.h."
23 #include <stdatomic.h>
25 #define OMIT_STANDARD_ATOMIC_TYPES 1
26 #define ATOMIC(TYPE) _Atomic(TYPE)
27 #include "ovs-atomic-types.h"
29 #define atomic_read(SRC, DST) \
30 atomic_read_explicit(SRC, DST, memory_order_seq_cst)
31 #define atomic_read_explicit(SRC, DST, ORDER) \
32 (*(DST) = atomic_load_explicit(SRC, ORDER), \
35 #define atomic_add(RMW, ARG, ORIG) \
36 atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
37 #define atomic_sub(RMW, ARG, ORIG) \
38 atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
39 #define atomic_or(RMW, ARG, ORIG) \
40 atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
41 #define atomic_xor(RMW, ARG, ORIG) \
42 atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
43 #define atomic_and(RMW, ARG, ORIG) \
44 atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
46 #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
47 (*(ORIG) = atomic_fetch_add_explicit(RMW, ARG, ORDER), (void) 0)
48 #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
49 (*(ORIG) = atomic_fetch_sub_explicit(RMW, ARG, ORDER), (void) 0)
50 #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
51 (*(ORIG) = atomic_fetch_or_explicit(RMW, ARG, ORDER), (void) 0)
52 #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
53 (*(ORIG) = atomic_fetch_xor_explicit(RMW, ARG, ORDER), (void) 0)
54 #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
55 (*(ORIG) = atomic_fetch_and_explicit(RMW, ARG, ORDER), (void) 0)
58 atomic_flag_init(volatile atomic_flag *object OVS_UNUSED)
64 atomic_flag_destroy(volatile atomic_flag *object OVS_UNUSED)