summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/atomic.h
blob: 3b62cb10cb8531fab737578b3a0be0ee236b9477 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
 * @file  rtems/score/atomic.h
 * 
 * This include file defines the interface for all the atomic
 * operations which can be used in the synchronization primitives
 * or in the lock-less algorithms. You should not use these API
 * in the other components directly. 
 */

/*
 * COPYRIGHT (c) 2012 Deng Hengyi.
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_ATOMIC_H
#define _RTEMS_SCORE_ATOMIC_H

#include <rtems/score/cpuatomic.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup RTEMS atomic interface
 *
 */

/**@{*/

/**
 * @brief the enumeration Atomic_Memory_barrier specifies the detailed regular
 * memory synchronization operations used in the atomic operation API 
 * definitions.  
 */
typedef enum {
  /** no operation orders memory. */
  ATOMIC_RELAXED_BARRIER,
  /** a load operation performs an acquire operation on the affected memory
  * location. This flag guarantees that the effects of load operation are 
  * completed before the effects of any later data accesses.
  */
  ATOMIC_ACQUIRE_BARRIER,
  /** a store operation performs a release operation on the affected memory
  * location. This flag guarantee that all effects of all previous data 
  * accesses are completed before the store operation takes place.
  */
  ATOMIC_RELEASE_BARRIER
} Atomic_Memory_barrier;

/**
 * @brief Atomically load an atomic type value from address @a address with
 * a type of Atomic_Memory_barrier @a memory_barrier. The @a memory_barrier
 * shall not be ATOMIC_RELEASE_BARRIER.
 */
RTEMS_INLINE_ROUTINE Atomic_Int _Atomic_Load_int(
  volatile Atomic_Int *address,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE Atomic_Long _Atomic_Load_long(
  volatile Atomic_Long *address,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE Atomic_Pointer _Atomic_Load_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE Atomic_Int32 _Atomic_Load_32(
  volatile Atomic_Int32 *address,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE Atomic_Int64 _Atomic_Load_64(
  volatile Atomic_Int64 *address,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically store an atomic type value @a value into address @a 
 * address with a type of Atomic_Memory_barrier @a memory_barrier. The @a 
 * memory_barrier shall not be ATOMIC_ACQUIRE_BARRIER.
 */
RTEMS_INLINE_ROUTINE void _Atomic_Store_int(
  volatile Atomic_Int *address,
  Atomic_Int value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Store_long(
  volatile Atomic_Long *address,
  Atomic_Long value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Store_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Store_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Store_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 value,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically load-add-store an atomic type value @a value into address
 * @a address with a type of Atomic_Memory_barrier @a memory_barrier.
 */
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_int(
  volatile Atomic_Int *address,
  Atomic_Int value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_long(
  volatile Atomic_Long *address,
  Atomic_Long value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_add_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 value,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically load-sub-store an atomic type value @a value into address
 * @a address with a type of Atomic_Memory_barrier @a memory_barrier.
 */
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_int(
  volatile Atomic_Int *address,
  Atomic_Int value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_long(
  volatile Atomic_Long *address,
  Atomic_Long value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_sub_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 value,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically load-or-store an atomic type value @a value into address
 * @a address with a type of Atomic_Memory_barrier @a memory_barrier.
 */
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_int(
  volatile Atomic_Int *address,
  Atomic_Int value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_long(
  volatile Atomic_Long *address,
  Atomic_Long value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_or_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 value,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically load-and-store an atomic type value @a value into address
 * @a address with a type of Atomic_Memory_barrier @a memory_barrier.
 */
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_int(
  volatile Atomic_Int *address,
  Atomic_Int value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_long(
  volatile Atomic_Long *address,
  Atomic_Long value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE void _Atomic_Fetch_and_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 value,
  Atomic_Memory_barrier memory_barrier
);

/**
 * @brief Atomically compare the value stored at @a address with @a 
 * old_value and if the two values are equal, update the value of @a 
 * address with @a new_value. Returns zero if the compare failed, 
 * nonzero otherwise. The operation uses a type of Atomic_Memory_barrier
 * @a memory_barrier.
 */
RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_int(
  volatile Atomic_Int *address,
  Atomic_Int old_value,
  Atomic_Int new_value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_long(
  volatile Atomic_Long *address,
  Atomic_Long old_value,
  Atomic_Long new_value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_ptr(
  volatile Atomic_Pointer *address,
  Atomic_Pointer old_value,
  Atomic_Pointer new_value,
  Atomic_Memory_barrier memory_barrier  
);
RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_32(
  volatile Atomic_Int32 *address,
  Atomic_Int32 old_value,
  Atomic_Int32 new_value,
  Atomic_Memory_barrier memory_barrier
);
RTEMS_INLINE_ROUTINE int _Atomic_Compare_exchange_64(
  volatile Atomic_Int64 *address,
  Atomic_Int64 old_value,
  Atomic_Int64 new_value,
  Atomic_Memory_barrier memory_barrier
);

#include <rtems/score/atomic.inl>

#ifdef __cplusplus
}
#endif

/**@}*/
#endif
/*  end of include file */