1 | /** |
---|
2 | * @file rtems/score/atomic.h |
---|
3 | * |
---|
4 | * This include file defines the interface for all the atomic |
---|
5 | * operations which can be used in the synchronization primitives |
---|
6 | * or in the lock-less algorithms. You should not use these API |
---|
7 | * in the other components directly. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 2012 Deng Hengyi. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_ATOMIC_H |
---|
19 | #define _RTEMS_SCORE_ATOMIC_H |
---|
20 | |
---|
21 | #include <rtems/score/cpuatomic.h> |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif |
---|
26 | |
---|
27 | /** |
---|
28 | * @defgroup RTEMS atomic interface |
---|
29 | * |
---|
30 | */ |
---|
31 | |
---|
32 | /**@{*/ |
---|
33 | |
---|
34 | /** |
---|
35 | * @brief the enumeration Atomic_Memory_barrier specifies the detailed regular |
---|
36 | * memory synchronization operations used in the atomic operation API |
---|
37 | * definitions. |
---|
38 | */ |
---|
39 | typedef enum { |
---|
40 | /** no operation orders memory. */ |
---|
41 | ATOMIC_RELAXED_BARRIER, |
---|
42 | /** a load operation performs an acquire operation on the affected memory |
---|
43 | * location. This flag guarantees that the effects of load operation are |
---|
44 | * completed before the effects of any later data accesses. |
---|
45 | */ |
---|
46 | ATOMIC_ACQUIRE_BARRIER, |
---|
47 | /** a store operation performs a release operation on the affected memory |
---|
48 | * location. This flag guarantee that all effects of all previous data |
---|
49 | * accesses are completed before the store operation takes place. |
---|
50 | */ |
---|
51 | ATOMIC_RELEASE_BARRIER |
---|
52 | } Atomic_Memory_barrier; |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief Atomically load an atomic type value from address @a address with |
---|
56 | * a type of Atomic_Memory_barrier @a memory_barrier. The @a memory_barrier |
---|
57 | * shall not be ATOMIC_RELEASE_BARRIER. |
---|
58 | */ |
---|
59 | RTEMS_INLINE_ROUTINE Atomic_Int _Atomic_Load_int( |
---|
60 | volatile Atomic_Int *address, |
---|
61 | Atomic_Memory_barrier memory_barrier |
---|
62 | ); |
---|
63 | RTEMS_INLINE_ROUTINE Atomic_Long _Atomic_Load_long( |
---|
64 | volatile Atomic_Long *address, |
---|
65 | Atomic_Memory_barrier memory_barrier |
---|
66 | ); |
---|
67 | RTEMS_INLINE_ROUTINE Atomic_Pointer _Atomic_Load_ptr( |
---|
68 | volatile Atomic_Pointer *address, |
---|
69 | Atomic_Memory_barrier memory_barrier |
---|
70 | ); |
---|
71 | RTEMS_INLINE_ROUTINE Atomic_Int32 _Atomic_Load_32( |
---|
72 | volatile Atomic_Int32 *address, |
---|
73 | Atomic_Memory_barrier memory_barrier |
---|
74 | ); |
---|
75 | RTEMS_INLINE_ROUTINE Atomic_Int64 _Atomic_Load_64( |
---|
76 | volatile Atomic_Int64 *address, |
---|
77 | Atomic_Memory_barrier memory_barrier |
---|
78 | ); |
---|
79 | |
---|
80 | /** |
---|
81 | * @brief Atomically store an atomic type value @a value into address @a |
---|
82 | * address with a type of Atomic_Memory_barrier @a memory_barrier. The @a |
---|
83 | * memory_barrier shall not be ATOMIC_ACQUIRE_BARRIER. |
---|
84 | */ |
---|
85 | RTEMS_INLINE_ROUTINE void _Atomic_Store_int( |
---|
86 | volatile Atomic_Int *address, |
---|
87 | Atomic_Int value, |
---|
88 | Atomic_Memory_barrier memory_barrier |
---|
89 | ); |
---|
90 | RTEMS_INLINE_ROUTINE void _Atomic_Store_long( |
---|
91 | volatile Atomic_Long *address, |
---|
92 | Atomic_Long value, |
---|
93 | Atomic_Memory_barrier memory_barrier |
---|
94 | ); |
---|
95 | RTEMS_INLINE_ROUTINE void _Atomic_Store_ptr( |
---|
96 | volatile Atomic_Pointer *address, |
---|
97 | Atomic_Pointer value, |
---|
98 | Atomic_Memory_barrier memory_barrier |
---|
99 | ); |
---|
100 | RTEMS_INLINE_ROUTINE void _Atomic_Store_32( |
---|
101 | volatile Atomic_Int32 *address, |
---|
102 | Atomic_Int32 value, |
---|
103 | Atomic_Memory_barrier memory_barrier |
---|
104 | ); |
---|
105 | RTEMS_INLINE_ROUTINE void _Atomic_Store_64( |
---|
106 | volatile Atomic_Int64 *address, |
---|
107 | Atomic_Int64 value, |
---|
108 | Atomic_Memory_barrier memory_barrier |
---|
109 | ); |
---|
110 | |
---|
111 | /** |
---|
112 | * @brief Atomically load-add-store an atomic type value @a value into address |
---|
113 | * @a address with a type of Atomic_Memory_barrier @a memory_barrier. |
---|
114 | */ |
---|
115 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_int( |
---|
116 | volatile Atomic_Int *address, |
---|
117 | Atomic_Int value, |
---|
118 | Atomic_Memory_barrier memory_barrier |
---|
119 | ); |
---|
120 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_long( |
---|
121 | volatile Atomic_Long *address, |
---|
122 | Atomic_Long value, |
---|
123 | Atomic_Memory_barrier memory_barrier |
---|
124 | ); |
---|
125 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_ptr( |
---|
126 | volatile Atomic_Pointer *address, |
---|
127 | Atomic_Pointer value, |
---|
128 | Atomic_Memory_barrier memory_barrier |
---|
129 | ); |
---|
130 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_32( |
---|
131 | volatile Atomic_Int32 *address, |
---|
132 | Atomic_Int32 value, |
---|
133 | Atomic_Memory_barrier memory_barrier |
---|
134 | ); |
---|
135 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_64( |
---|
136 | volatile Atomic_Int64 *address, |
---|
137 | Atomic_Int64 value, |
---|
138 | Atomic_Memory_barrier memory_barrier |
---|
139 | ); |
---|
140 | |
---|
141 | /** |
---|
142 | * @brief Atomically load-sub-store an atomic type value @a value into address |
---|
143 | * @a address with a type of Atomic_Memory_barrier @a memory_barrier. |
---|
144 | */ |
---|
145 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_int( |
---|
146 | volatile Atomic_Int *address, |
---|
147 | Atomic_Int value, |
---|
148 | Atomic_Memory_barrier memory_barrier |
---|
149 | ); |
---|
150 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_long( |
---|
151 | volatile Atomic_Long *address, |
---|
152 | Atomic_Long value, |
---|
153 | Atomic_Memory_barrier memory_barrier |
---|
154 | ); |
---|
155 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_ptr( |
---|
156 | volatile Atomic_Pointer *address, |
---|
157 | Atomic_Pointer value, |
---|
158 | Atomic_Memory_barrier memory_barrier |
---|
159 | ); |
---|
160 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_32( |
---|
161 | volatile Atomic_Int32 *address, |
---|
162 | Atomic_Int32 value, |
---|
163 | Atomic_Memory_barrier memory_barrier |
---|
164 | ); |
---|
165 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_64( |
---|
166 | volatile Atomic_Int64 *address, |
---|
167 | Atomic_Int64 value, |
---|
168 | Atomic_Memory_barrier memory_barrier |
---|
169 | ); |
---|
170 | |
---|
171 | /** |
---|
172 | * @brief Atomically load-or-store an atomic type value @a value into address |
---|
173 | * @a address with a type of Atomic_Memory_barrier @a memory_barrier. |
---|
174 | */ |
---|
175 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_int( |
---|
176 | volatile Atomic_Int *address, |
---|
177 | Atomic_Int value, |
---|
178 | Atomic_Memory_barrier memory_barrier |
---|
179 | ); |
---|
180 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_long( |
---|
181 | volatile Atomic_Long *address, |
---|
182 | Atomic_Long value, |
---|
183 | Atomic_Memory_barrier memory_barrier |
---|
184 | ); |
---|
185 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_ptr( |
---|
186 | volatile Atomic_Pointer *address, |
---|
187 | Atomic_Pointer value, |
---|
188 | Atomic_Memory_barrier memory_barrier |
---|
189 | ); |
---|
190 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_32( |
---|
191 | volatile Atomic_Int32 *address, |
---|
192 | Atomic_Int32 value, |
---|
193 | Atomic_Memory_barrier memory_barrier |
---|
194 | ); |
---|
195 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_64( |
---|
196 | volatile Atomic_Int64 *address, |
---|
197 | Atomic_Int64 value, |
---|
198 | Atomic_Memory_barrier memory_barrier |
---|
199 | ); |
---|
200 | |
---|
201 | /** |
---|
202 | * @brief Atomically load-and-store an atomic type value @a value into address |
---|
203 | * @a address with a type of Atomic_Memory_barrier @a memory_barrier. |
---|
204 | */ |
---|
205 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_int( |
---|
206 | volatile Atomic_Int *address, |
---|
207 | Atomic_Int value, |
---|
208 | Atomic_Memory_barrier memory_barrier |
---|
209 | ); |
---|
210 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_long( |
---|
211 | volatile Atomic_Long *address, |
---|
212 | Atomic_Long value, |
---|
213 | Atomic_Memory_barrier memory_barrier |
---|
214 | ); |
---|
215 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_ptr( |
---|
216 | volatile Atomic_Pointer *address, |
---|
217 | Atomic_Pointer value, |
---|
218 | Atomic_Memory_barrier memory_barrier |
---|
219 | ); |
---|
220 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_32( |
---|
221 | volatile Atomic_Int32 *address, |
---|
222 | Atomic_Int32 value, |
---|
223 | Atomic_Memory_barrier memory_barrier |
---|
224 | ); |
---|
225 | RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_64( |
---|
226 | volatile Atomic_Int64 *address, |
---|
227 | Atomic_Int64 value, |
---|
228 | Atomic_Memory_barrier memory_barrier |
---|
229 | ); |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief Atomically compare the value stored at @a address with @a |
---|
233 | * old_value and if the two values are equal, update the value of @a |
---|
234 | * address with @a new_value. Returns zero if the compare failed, |
---|
235 | * nonzero otherwise. The operation uses a type of Atomic_Memory_barrier |
---|
236 | * @a memory_barrier. |
---|
237 | */ |
---|
238 | RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_int( |
---|
239 | volatile Atomic_Int *address, |
---|
240 | Atomic_Int old_value, |
---|
241 | Atomic_Int new_value, |
---|
242 | Atomic_Memory_barrier memory_barrier |
---|
243 | ); |
---|
244 | RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_long( |
---|
245 | volatile Atomic_Long *address, |
---|
246 | Atomic_Long old_value, |
---|
247 | Atomic_Long new_value, |
---|
248 | Atomic_Memory_barrier memory_barrier |
---|
249 | ); |
---|
250 | RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_ptr( |
---|
251 | volatile Atomic_Pointer *address, |
---|
252 | Atomic_Pointer old_value, |
---|
253 | Atomic_Pointer new_value, |
---|
254 | Atomic_Memory_barrier memory_barrier |
---|
255 | ); |
---|
256 | RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_32( |
---|
257 | volatile Atomic_Int32 *address, |
---|
258 | Atomic_Int32 old_value, |
---|
259 | Atomic_Int32 new_value, |
---|
260 | Atomic_Memory_barrier memory_barrier |
---|
261 | ); |
---|
262 | RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_64( |
---|
263 | volatile Atomic_Int64 *address, |
---|
264 | Atomic_Int64 old_value, |
---|
265 | Atomic_Int64 new_value, |
---|
266 | Atomic_Memory_barrier memory_barrier |
---|
267 | ); |
---|
268 | |
---|
269 | #include <rtems/score/atomic.inl> |
---|
270 | |
---|
271 | #ifdef __cplusplus |
---|
272 | } |
---|
273 | #endif |
---|
274 | |
---|
275 | /**@}*/ |
---|
276 | #endif |
---|
277 | /* end of include file */ |
---|