source: rtems/cpukit/score/include/rtems/score/atomic.h @ f68401e

4.115
Last change on this file since f68401e was 8b50a55, checked in by Sebastian Huber <sebastian.huber@…>, on 03/03/14 at 08:09:24

score: Add _Atomic_Fence()

  • Property mode set to 100644
File size: 9.5 KB
Line 
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-2013 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
24extern "C" {
25#endif
26
27/**
28 * @defgroup RTEMS atomic interface
29 *
30 */
31
32/**@{*/
33
34/**
35 * @brief atomic data initializer for static initialization.
36 */
37#define ATOMIC_INITIALIZER_UINT(value) CPU_ATOMIC_INITIALIZER_UINT(value)
38#define ATOMIC_INITIALIZER_ULONG(value) CPU_ATOMIC_INITIALIZER_ULONG(value)
39#define ATOMIC_INITIALIZER_PTR(value) CPU_ATOMIC_INITIALIZER_PTR(value)
40
41/**
42 * @brief Initializes an atomic flag object to the cleared state.
43 */
44#define ATOMIC_INITIALIZER_FLAG CPU_ATOMIC_INITIALIZER_FLAG
45
46static inline void _Atomic_Fence(
47  Atomic_Order order
48)
49{
50  _CPU_atomic_Fence( order );
51}
52
53/**
54 * @brief Initializes an atomic type value into a atomic object.
55 *
56 * @param object an atomic type pointer of object.
57 * @param pointer a pointer to be stored into object.
58 */
59static inline void _Atomic_Init_uint(
60  volatile Atomic_Uint *object,
61  unsigned int value
62)
63{
64  _CPU_atomic_Init_uint(object, value);
65}
66
67static inline void _Atomic_Init_ulong(
68  volatile Atomic_Ulong *object,
69  unsigned long value
70)
71{
72  _CPU_atomic_Init_ulong(object, value);
73}
74
75static inline void _Atomic_Init_ptr(
76  volatile Atomic_Pointer *object,
77  void *pointer
78)
79{
80  _CPU_atomic_Init_ptr(object, pointer);
81}
82
83/**
84 * @brief Atomically load an atomic type value from atomic object.
85 *
86 * @param object an atomic type pointer of object.
87 * @param order a type of Atomic_Order.
88 *
89 * The order shall not be ATOMIC_ORDER_RELEASE.
90 */
91static inline unsigned int _Atomic_Load_uint(
92  volatile Atomic_Uint *object,
93  Atomic_Order order
94)
95{
96  return _CPU_atomic_Load_uint( object, order );
97}
98
99static inline unsigned long _Atomic_Load_ulong(
100  volatile Atomic_Ulong *object,
101  Atomic_Order order
102)
103{
104  return _CPU_atomic_Load_ulong( object, order );
105}
106
107static inline void *_Atomic_Load_ptr(
108  volatile Atomic_Pointer *object,
109  Atomic_Order order
110)
111{
112  return _CPU_atomic_Load_ptr( object, order );
113}
114
115/**
116 * @brief Atomically store an atomic type value into a atomic object.
117 *
118 * @param object an atomic type pointer of object.
119 * @param value a value to be stored into object.
120 * @param order a type of Atomic_Order.
121 *
122 * The order shall not be ATOMIC_ORDER_ACQUIRE.
123 */
124static inline void _Atomic_Store_uint(
125  volatile Atomic_Uint *object,
126  unsigned int value,
127  Atomic_Order order
128)
129{
130  _CPU_atomic_Store_uint( object, value, order );
131}
132
133static inline void _Atomic_Store_ulong(
134  volatile Atomic_Ulong *object,
135  unsigned long value,
136  Atomic_Order order
137)
138{
139  _CPU_atomic_Store_ulong( object, value, order );
140}
141
142static inline void _Atomic_Store_ptr(
143  volatile Atomic_Pointer *object,
144  void *pointer,
145  Atomic_Order order
146)
147{
148  _CPU_atomic_Store_ptr( object, pointer, order );
149}
150
151/**
152 * @brief Atomically load-add-store an atomic type value into object
153 *
154 * @param object a atomic type pointer of object.
155 * @param value a value to be add and store into object.
156 * @param order a type of Atomic_Order.
157 *
158 * @retval a result value before add ops.
159 */
160static inline unsigned int _Atomic_Fetch_add_uint(
161  volatile Atomic_Uint *object,
162  unsigned int value,
163  Atomic_Order order
164)
165{
166  return _CPU_atomic_Fetch_add_uint( object, value, order );
167}
168
169static inline unsigned long _Atomic_Fetch_add_ulong(
170  volatile Atomic_Ulong *object,
171  unsigned long value,
172  Atomic_Order order
173)
174{
175  return _CPU_atomic_Fetch_add_ulong( object, value, order );
176}
177
178static inline uintptr_t _Atomic_Fetch_add_ptr(
179  volatile Atomic_Pointer *object,
180  uintptr_t value,
181  Atomic_Order order
182)
183{
184  return _CPU_atomic_Fetch_add_ptr( object, value, order );
185}
186
187/**
188 * @brief Atomically load-sub-store an atomic type value into object
189 *
190 * @param object a atomic type pointer of object.
191 * @param value a value to be sub and store into object.
192 * @param order a type of Atomic_Order.
193 *
194 * @retval a result value before sub ops.
195 */
196static inline unsigned int _Atomic_Fetch_sub_uint(
197  volatile Atomic_Uint *object,
198  unsigned int value,
199  Atomic_Order order
200)
201{
202  return _CPU_atomic_Fetch_sub_uint( object, value, order );
203}
204
205static inline unsigned long _Atomic_Fetch_sub_ulong(
206  volatile Atomic_Ulong *object,
207  unsigned long value,
208  Atomic_Order order
209)
210{
211  return _CPU_atomic_Fetch_sub_ulong( object, value, order );
212}
213
214static inline uintptr_t _Atomic_Fetch_sub_ptr(
215  volatile Atomic_Pointer *object,
216  uintptr_t value,
217  Atomic_Order order
218)
219{
220  return _CPU_atomic_Fetch_sub_ptr( object, value, order );
221}
222
223/**
224 * @brief Atomically load-or-store an atomic type value into object
225 *
226 * @param object a atomic type pointer of object.
227 * @param value a value to be or and store into object.
228 * @param order a type of Atomic_Order.
229 *
230 * @retval a result value before or ops.
231 */
232static inline unsigned int _Atomic_Fetch_or_uint(
233  volatile Atomic_Uint *object,
234  unsigned int value,
235  Atomic_Order order
236)
237{
238  return _CPU_atomic_Fetch_or_uint( object, value, order );
239}
240
241static inline unsigned long _Atomic_Fetch_or_ulong(
242  volatile Atomic_Ulong *object,
243  unsigned long value,
244  Atomic_Order order
245)
246{
247  return _CPU_atomic_Fetch_or_ulong( object, value, order );
248}
249
250static inline uintptr_t _Atomic_Fetch_or_ptr(
251  volatile Atomic_Pointer *object,
252  uintptr_t value,
253  Atomic_Order order
254)
255{
256  return _CPU_atomic_Fetch_or_ptr( object, value, order );
257}
258
259/**
260 * @brief Atomically load-and-store an atomic type value into object
261 *
262 * @param object a atomic type pointer of object.
263 * @param value a value to be and and store into object.
264 * @param order a type of Atomic_Order.
265 *
266 * @retval a result value before and ops.
267 */
268static inline unsigned int _Atomic_Fetch_and_uint(
269  volatile Atomic_Uint *object,
270  unsigned int value,
271  Atomic_Order order
272)
273{
274  return _CPU_atomic_Fetch_and_uint( object, value, order );
275}
276
277static inline unsigned long _Atomic_Fetch_and_ulong(
278  volatile Atomic_Ulong *object,
279  unsigned long value,
280  Atomic_Order order
281)
282{
283  return _CPU_atomic_Fetch_and_ulong( object, value, order );
284}
285
286static inline uintptr_t _Atomic_Fetch_and_ptr(
287  volatile Atomic_Pointer *object,
288  uintptr_t value,
289  Atomic_Order order
290)
291{
292  return _CPU_atomic_Fetch_and_ptr( object, value, order );
293}
294
295/**
296 * @brief Atomically exchange an atomic type value into object
297 *
298 * @param object a atomic type pointer of object.
299 * @param value a value to exchange and and store into object.
300 * @param order a type of Atomic_Order.
301 *
302 * @retval a result value before exchange ops.
303 */
304static inline unsigned int _Atomic_Exchange_uint(
305 volatile Atomic_Uint *object,
306 unsigned int value,
307 Atomic_Order order
308)
309{
310  return _CPU_atomic_Exchange_uint( object, value, order );
311}
312
313static inline unsigned long _Atomic_Exchange_ulong(
314 volatile Atomic_Ulong *object,
315 unsigned long value,
316 Atomic_Order order
317)
318{
319  return _CPU_atomic_Exchange_ulong( object, value, order );
320}
321
322static inline void *_Atomic_Exchange_ptr(
323 volatile Atomic_Pointer *object,
324 void *pointer,
325 Atomic_Order order
326)
327{
328  return _CPU_atomic_Exchange_ptr( object, pointer, order );
329}
330
331/**
332 * @brief Atomically compare the value stored at object with a
333 * old_value and if the two values are equal, update the value of a
334 * address with a new_value
335 *
336 * @param object a atomic type pointer of object.
337 * @param old_value pointer of a value.
338 * @param new_value a atomic type value.
339 * @param order_succ a type of Atomic_Order for successful exchange.
340 * @param order_fail a type of Atomic_Order for failed exchange.
341 *
342 * @retval true if the compare exchange successully.
343 * @retval false if the compare exchange failed.
344 */
345static inline bool _Atomic_Compare_exchange_uint(
346  volatile Atomic_Uint *object,
347  unsigned int *old_value,
348  unsigned int new_value,
349  Atomic_Order order_succ,
350  Atomic_Order order_fail
351)
352{
353  return _CPU_atomic_Compare_exchange_uint( object, old_value, new_value,
354    order_succ, order_fail );
355}
356
357static inline bool _Atomic_Compare_exchange_ulong(
358  volatile Atomic_Ulong *object,
359  unsigned long *old_value,
360  unsigned long new_value,
361  Atomic_Order order_succ,
362  Atomic_Order order_fail
363)
364{
365  return _CPU_atomic_Compare_exchange_ulong( object, old_value, new_value,
366    order_succ, order_fail );
367}
368
369static inline bool _Atomic_Compare_exchange_ptr(
370  volatile Atomic_Pointer *object,
371  void **old_pointer,
372  void *new_pointer,
373  Atomic_Order order_succ,
374  Atomic_Order order_fail
375)
376{
377  return _CPU_atomic_Compare_exchange_ptr( object, old_pointer, new_pointer,
378    order_succ, order_fail );
379}
380
381/**
382 * @brief Atomically clears an atomic flag.
383 *
384 * @param[in, out] object Pointer to the atomic flag object.
385 * @param[in] order The atomic memory order.
386 *
387 */
388static inline void _Atomic_Flag_clear(
389  volatile Atomic_Flag *object,
390  Atomic_Order order
391)
392{
393  _CPU_atomic_Flag_clear( object, order );
394}
395
396/**
397 * @brief Atomically tests and sets an atomic flag.
398 *
399 * @param[in, out] object Pointer to the atomic flag object.
400 * @param[in] order The atomic memory order.
401 *
402 * @retval true The atomic flag was already set.
403 * @retval false Otherwise.
404 */
405static inline bool _Atomic_Flag_test_and_set(
406  volatile Atomic_Flag *object,
407  Atomic_Order order
408)
409{
410  return _CPU_atomic_Flag_test_and_set( object, order );
411}
412
413#ifdef __cplusplus
414}
415#endif
416
417/**@}*/
418#endif
419/*  end of include file */
Note: See TracBrowser for help on using the repository browser.