1 /*
2  * Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * @file	atomic.h
9  * @brief	Atomic primitives for libmetal.
10  */
11 
12 #ifndef __METAL_ATOMIC__H__
13 #define __METAL_ATOMIC__H__
14 
15 #include <metal/config.h>
16 
17 #if defined(__cplusplus)
18 # include <cstdint>
19 
20 /*
21  * <atomic> has the same functionality as <stdatomic.h> but all members are only
22  * accessible in the std namespace. As the rest of libmetal is pure C, it does
23  * not know about namespaces, even when compiled as part of a C++ file. So we
24  * just export the members of <atomic> into the global namespace.
25  */
26 # include <atomic>
27 using std::atomic_flag;
28 using std::memory_order;
29 using std::memory_order_relaxed;
30 using std::memory_order_consume;
31 using std::memory_order_acquire;
32 using std::memory_order_release;
33 using std::memory_order_acq_rel;
34 using std::memory_order_seq_cst;
35 
36 using std::atomic_bool;
37 using std::atomic_char;
38 using std::atomic_schar;
39 using std::atomic_uchar;
40 using std::atomic_short;
41 using std::atomic_ushort;
42 using std::atomic_int;
43 using std::atomic_uint;
44 using std::atomic_long;
45 using std::atomic_ulong;
46 using std::atomic_llong;
47 using std::atomic_ullong;
48 using std::atomic_char16_t;
49 using std::atomic_char32_t;
50 using std::atomic_wchar_t;
51 using std::atomic_int_least8_t;
52 using std::atomic_uint_least8_t;
53 using std::atomic_int_least16_t;
54 using std::atomic_uint_least16_t;
55 using std::atomic_int_least32_t;
56 using std::atomic_uint_least32_t;
57 using std::atomic_int_least64_t;
58 using std::atomic_uint_least64_t;
59 using std::atomic_int_fast8_t;
60 using std::atomic_uint_fast8_t;
61 using std::atomic_int_fast16_t;
62 using std::atomic_uint_fast16_t;
63 using std::atomic_int_fast32_t;
64 using std::atomic_uint_fast32_t;
65 using std::atomic_int_fast64_t;
66 using std::atomic_uint_fast64_t;
67 using std::atomic_intptr_t;
68 using std::atomic_uintptr_t;
69 using std::atomic_size_t;
70 using std::atomic_ptrdiff_t;
71 using std::atomic_intmax_t;
72 using std::atomic_uintmax_t;
73 
74 using std::atomic_flag_test_and_set;
75 using std::atomic_flag_test_and_set_explicit;
76 using std::atomic_flag_clear;
77 using std::atomic_flag_clear_explicit;
78 using std::atomic_init;
79 using std::atomic_is_lock_free;
80 using std::atomic_store;
81 using std::atomic_store_explicit;
82 using std::atomic_load;
83 using std::atomic_load_explicit;
84 using std::atomic_exchange;
85 using std::atomic_exchange_explicit;
86 using std::atomic_compare_exchange_strong;
87 using std::atomic_compare_exchange_strong_explicit;
88 using std::atomic_compare_exchange_weak;
89 using std::atomic_compare_exchange_weak_explicit;
90 using std::atomic_fetch_add;
91 using std::atomic_fetch_add_explicit;
92 using std::atomic_fetch_sub;
93 using std::atomic_fetch_sub_explicit;
94 using std::atomic_fetch_or;
95 using std::atomic_fetch_or_explicit;
96 using std::atomic_fetch_xor;
97 using std::atomic_fetch_xor_explicit;
98 using std::atomic_fetch_and;
99 using std::atomic_fetch_and_explicit;
100 using std::atomic_thread_fence;
101 using std::atomic_signal_fence;
102 
103 #elif defined(HAVE_STDATOMIC_H) && !defined(__ARMCC_VERSION) && \
104 !defined(__STDC_NO_ATOMICS__)
105 # include <stdint.h>
106 # include <stdatomic.h>
107 #elif defined(__GNUC__)
108 # include <metal/compiler/gcc/atomic.h>
109 #else
110 #if defined(HAVE_PROCESSOR_ATOMIC_H)
111 # include <metal/processor/@PROJECT_PROCESSOR@/atomic.h>
112 #else
113 # include <metal/processor/generic/atomic.h>
114 #endif /* defined(HAVE_PROCESSOR_ATOMIC_H) */
115 #endif
116 
117 #endif /* __METAL_ATOMIC__H__ */
118