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

4.115
Last change on this file since ad56361 was 945853b7, checked in by Sebastian Huber <sebastian.huber@…>, on 02/13/14 at 14:38:52

score: Add Atomic_Uint

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