source: rtems/cpukit/score/include/rtems/score/atomic.h @ 697d31e

4.115
Last change on this file since 697d31e was 697d31e, checked in by WeiY <wei.a.yang@…>, on 08/25/13 at 13:45:41

add atomic init function

  • Property mode set to 100644
File size: 7.9 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_PTR(value) CPU_ATOMIC_INITIALIZER_PTR(value)
39#define ATOMIC_INITIALIZER_FLAG(value) CPU_ATOMIC_INITIALIZER_FLAG(value)
40
41/**
42 * @brief Initializes an atomic type value into a atomic object.
43 *
44 * @param object an atomic type pointer of object.
45 * @param value a value to be stored into object.
46 */
47RTEMS_INLINE_ROUTINE void _Atomic_Init_uint(
48  volatile Atomic_Uint *object,
49  uint_fast32_t value
50)
51{
52  _CPU_atomic_Init_uint(object, value);
53}
54
55RTEMS_INLINE_ROUTINE void _Atomic_Init_ptr(
56  volatile Atomic_Pointer *object,
57  uintptr_t value
58)
59{
60  _CPU_atomic_Init_ptr(object, value);
61}
62
63RTEMS_INLINE_ROUTINE void _Atomic_Init_flag(
64  volatile Atomic_Flag *object,
65  _Bool value
66)
67{
68  _CPU_atomic_Init_flag(object, value);
69}
70
71/**
72 * @brief Atomically load an atomic type value from atomic object.
73 *
74 * @param object an atomic type pointer of object.
75 * @param order a type of Atomic_Order.
76 *
77 * The order shall not be ATOMIC_ORDER_RELEASE.
78 */
79RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Load_uint(
80  volatile Atomic_Uint *object,
81  Atomic_Order order
82)
83{
84  return _CPU_atomic_Load_uint( object, order );
85}
86
87RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Load_ptr(
88  volatile Atomic_Pointer *object,
89  Atomic_Order order
90)
91{
92  return _CPU_atomic_Load_ptr( object, order );
93}
94
95/**
96 * @brief Atomically store an atomic type value into a atomic object.
97 *
98 * @param object an atomic type pointer of object.
99 * @param value a value to be stored into object.
100 * @param order a type of Atomic_Order.
101 *
102 * The order shall not be ATOMIC_ORDER_ACQUIRE.
103 */
104RTEMS_INLINE_ROUTINE void _Atomic_Store_uint(
105  volatile Atomic_Uint *object,
106  uint_fast32_t value,
107  Atomic_Order order
108)
109{
110  _CPU_atomic_Store_uint( object, value, order );
111}
112
113RTEMS_INLINE_ROUTINE void _Atomic_Store_ptr(
114  volatile Atomic_Pointer *object,
115  uintptr_t value,
116  Atomic_Order order
117)
118{
119  _CPU_atomic_Store_ptr( object, value, order );
120}
121
122/**
123 * @brief Atomically load-add-store an atomic type value into object
124 *
125 * @param object a atomic type pointer of object.
126 * @param value a value to be add and store into object.
127 * @param order a type of Atomic_Order.
128 *
129 * @retval a result value before add ops.
130 */
131RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Fetch_add_uint(
132  volatile Atomic_Uint *object,
133  uint_fast32_t value,
134  Atomic_Order order
135)
136{
137  return _CPU_atomic_Fetch_add_uint( object, value, order );
138}
139
140RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Fetch_add_ptr(
141  volatile Atomic_Pointer *object,
142  uintptr_t value,
143  Atomic_Order order
144)
145{
146  return _CPU_atomic_Fetch_add_ptr( object, value, order );
147}
148
149/**
150 * @brief Atomically load-sub-store an atomic type value into object
151 *
152 * @param object a atomic type pointer of object.
153 * @param value a value to be sub and store into object.
154 * @param order a type of Atomic_Order.
155 *
156 * @retval a result value before sub ops.
157 */
158RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Fetch_sub_uint(
159  volatile Atomic_Uint *object,
160  uint_fast32_t value,
161  Atomic_Order order
162)
163{
164  return _CPU_atomic_Fetch_sub_uint( object, value, order );
165}
166
167RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Fetch_sub_ptr(
168  volatile Atomic_Pointer *object,
169  uintptr_t value,
170  Atomic_Order order
171)
172{
173  return _CPU_atomic_Fetch_sub_ptr( object, value, order );
174}
175
176/**
177 * @brief Atomically load-or-store an atomic type value into object
178 *
179 * @param object a atomic type pointer of object.
180 * @param value a value to be or and store into object.
181 * @param order a type of Atomic_Order.
182 *
183 * @retval a result value before or ops.
184 */
185RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Fetch_or_uint(
186  volatile Atomic_Uint *object,
187  uint_fast32_t value,
188  Atomic_Order order
189)
190{
191  return _CPU_atomic_Fetch_or_uint( object, value, order );
192}
193
194RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Fetch_or_ptr(
195  volatile Atomic_Pointer *object,
196  uintptr_t value,
197  Atomic_Order order
198)
199{
200  return _CPU_atomic_Fetch_or_ptr( object, value, order );
201}
202
203/**
204 * @brief Atomically load-and-store an atomic type value into object
205 *
206 * @param object a atomic type pointer of object.
207 * @param value a value to be and and store into object.
208 * @param order a type of Atomic_Order.
209 *
210 * @retval a result value before and ops.
211 */
212RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Fetch_and_uint(
213  volatile Atomic_Uint *object,
214  uint_fast32_t value,
215  Atomic_Order order
216)
217{
218  return _CPU_atomic_Fetch_and_uint( object, value, order );
219}
220
221RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Fetch_and_ptr(
222  volatile Atomic_Pointer *object,
223  uintptr_t value,
224  Atomic_Order order
225)
226{
227  return _CPU_atomic_Fetch_and_ptr( object, value, order );
228}
229
230/**
231 * @brief Atomically exchange an atomic type value into object
232 *
233 * @param object a atomic type pointer of object.
234 * @param value a value to exchange and and store into object.
235 * @param order a type of Atomic_Order.
236 *
237 * @retval a result value before exchange ops.
238 */
239RTEMS_INLINE_ROUTINE uint_fast32_t _Atomic_Exchange_uint(
240 volatile Atomic_Uint *object,
241 uint_fast32_t value,
242 Atomic_Order order
243)
244{
245  return _CPU_atomic_Exchange_uint( object, value, order );
246}
247
248RTEMS_INLINE_ROUTINE uintptr_t _Atomic_Exchange_ptr(
249 volatile Atomic_Pointer *object,
250 uintptr_t value,
251 Atomic_Order order
252)
253{
254  return _CPU_atomic_Exchange_ptr( object, value, order );
255}
256
257/**
258 * @brief Atomically compare the value stored at object with a
259 * old_value and if the two values are equal, update the value of a
260 * address with a new_value
261 *
262 * @param object a atomic type pointer of object.
263 * @param old_value pointer of a value.
264 * @param new_value a atomic type value.
265 * @param order_succ a type of Atomic_Order for successful exchange.
266 * @param order_fail a type of Atomic_Order for failed exchange.
267 *
268 * @retval true if the compare exchange successully.
269 * @retval false if the compare exchange failed.
270 */
271RTEMS_INLINE_ROUTINE bool _Atomic_Compare_exchange_uint(
272  volatile Atomic_Uint *object,
273  uint_fast32_t *old_value,
274  uint_fast32_t new_value,
275  Atomic_Order order_succ,
276  Atomic_Order order_fail
277)
278{
279  return _CPU_atomic_Compare_exchange_uint( object, old_value, new_value,
280    order_succ, order_fail );
281}
282
283RTEMS_INLINE_ROUTINE bool _Atomic_Compare_exchange_ptr(
284  volatile Atomic_Pointer *object,
285  uintptr_t *old_value,
286  uintptr_t new_value,
287  Atomic_Order order_succ,
288  Atomic_Order order_fail
289)
290{
291  return _CPU_atomic_Compare_exchange_ptr( object, old_value, new_value,
292    order_succ, order_fail );
293}
294
295/**
296 * @brief Atomically clear the value of an atomic flag type object.
297 *
298 * @param[in, out] object an atomic flag type pointer of object.
299 * @param order a type of Atomic_Order.
300 *
301 */
302RTEMS_INLINE_ROUTINE void _Atomic_Clear_flag(
303 volatile Atomic_Flag *object,
304 Atomic_Order order
305)
306{
307  _CPU_atomic_Clear_flag( object, order );
308}
309
310/**
311 * @brief Atomically test and clear the value of an atomic flag type object.
312 *
313 * @param[in, out] object an atomic flag type pointer of object.
314 * @param order a type of Atomic_Order.
315 *
316 * @retval true if the test and set successully.
317 * @retval false if the test and set failed.
318 */
319RTEMS_INLINE_ROUTINE bool _Atomic_Test_set_flag(
320 volatile Atomic_Flag *object,
321 Atomic_Order order
322)
323{
324  return _CPU_atomic_Test_set_flag( object, order );
325}
326
327#ifdef __cplusplus
328}
329#endif
330
331/**@}*/
332#endif
333/*  end of include file */
Note: See TracBrowser for help on using the repository browser.