• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_
18 #define INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_
19 
20 // Problem: C++11 and C11 use a different syntax for atomics and the C11 syntax
21 // is not supported in C++11.
22 //
23 // This header bridges the gap.
24 //
25 // This assumes that C++11 atomics are binary compatible with C11 atomics. While
26 // this is technically not required by the standards, reasonable compilers
27 // appear to guarantee this.
28 
29 #ifdef __cplusplus
30 #include <atomic>
31 #else
32 #include <stdatomic.h>
33 #endif
34 
35 #ifdef __cplusplus
36 #define PERFETTO_ATOMIC(TYPE) std::atomic<TYPE>
37 #else
38 #define PERFETTO_ATOMIC(TYPE) _Atomic(TYPE)
39 #endif
40 
41 #ifdef __cplusplus
42 #define PERFETTO_ATOMIC_LOAD std::atomic_load
43 #define PERFETTO_ATOMIC_LOAD_EXPLICIT std::atomic_load_explicit
44 #define PERFETTO_ATOMIC_STORE std::atomic_store
45 #define PERFETTO_ATOMIC_STORE_EXPLICIT std::atomic_store_explicit
46 
47 #define PERFETTO_MEMORY_ORDER_ACQ_REL std::memory_order_acq_rel
48 #define PERFETTO_MEMORY_ORDER_ACQUIRE std::memory_order_acquire
49 #define PERFETTO_MEMORY_ORDER_CONSUME std::memory_order_consume
50 #define PERFETTO_MEMORY_ORDER_RELAXED std::memory_order_relaxed
51 #define PERFETTO_MEMORY_ORDER_RELEASE std::memory_order_release
52 #define PERFETTO_MEMORY_ORDER_SEQ_CST std::memory_order_seq_cst
53 #else
54 #define PERFETTO_ATOMIC_LOAD atomic_load
55 #define PERFETTO_ATOMIC_LOAD_EXPLICIT atomic_load_explicit
56 #define PERFETTO_ATOMIC_STORE atomic_store
57 #define PERFETTO_ATOMIC_STORE_EXPLICIT atomic_store_explicit
58 
59 #define PERFETTO_MEMORY_ORDER_ACQ_REL memory_order_acq_rel
60 #define PERFETTO_MEMORY_ORDER_ACQUIRE memory_order_acquire
61 #define PERFETTO_MEMORY_ORDER_CONSUME memory_order_consume
62 #define PERFETTO_MEMORY_ORDER_RELAXED memory_order_relaxed
63 #define PERFETTO_MEMORY_ORDER_RELEASE memory_order_release
64 #define PERFETTO_MEMORY_ORDER_SEQ_CST memory_order_seq_cst
65 #endif
66 
67 #endif  // INCLUDE_PERFETTO_PUBLIC_ABI_ATOMIC_H_
68