Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_atomic-sync.h
Go to the documentation of this file.
1
33#if defined (__ia64) && defined (__INTEL_COMPILER)
34# include <ia64intrin.h>
35#endif
36
38
39inline char
40__rw_atomic_preincrement (char &__x, bool)
41{
42 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
43 return __sync_add_and_fetch (&__x, 1);
44}
45
46
47inline signed char
48__rw_atomic_preincrement (signed char &__x, bool)
49{
50 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
51 return __sync_add_and_fetch (&__x, 1);
52}
53
54
55inline unsigned char
56__rw_atomic_preincrement (unsigned char &__x, bool)
57{
58 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
59 return __sync_add_and_fetch (&__x, 1);
60}
61
62
63inline short
64__rw_atomic_preincrement (short &__x, bool)
65{
66 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
67 return __sync_add_and_fetch (&__x, 1);
68}
69
70
71inline unsigned short
72__rw_atomic_preincrement (unsigned short &__x, bool)
73{
74 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
75 return __sync_add_and_fetch (&__x, 1);
76}
77
78
79inline int
80__rw_atomic_preincrement (int &__x, bool)
81{
82 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
83 return __sync_add_and_fetch (&__x, 1);
84}
85
86
87inline unsigned int
88__rw_atomic_preincrement (unsigned int &__x, bool)
89{
90 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
91 return __sync_add_and_fetch (&__x, 1);
92}
93
94
95inline char
96__rw_atomic_predecrement (char &__x, bool)
97{
98 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
99 return __sync_sub_and_fetch (&__x, 1);
100}
101
102
103inline signed char
104__rw_atomic_predecrement (signed char &__x, bool)
105{
106 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
107 return __sync_sub_and_fetch (&__x, 1);
108}
109
110
111inline unsigned char
112__rw_atomic_predecrement (unsigned char &__x, bool)
113{
114 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
115 return __sync_sub_and_fetch (&__x, 1);
116}
117
118
119inline short
120__rw_atomic_predecrement (short &__x, bool)
121{
122 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
123 return __sync_sub_and_fetch (&__x, 1);
124}
125
126
127inline unsigned short
128__rw_atomic_predecrement (unsigned short &__x, bool)
129{
130 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
131 return __sync_sub_and_fetch (&__x, 1);
132}
133
134
135inline int
136__rw_atomic_predecrement (int &__x, bool)
137{
138 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
139 return __sync_sub_and_fetch (&__x, 1);
140}
141
142
143inline unsigned int
144__rw_atomic_predecrement (unsigned int &__x, bool)
145{
146 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
147 return __sync_sub_and_fetch (&__x, 1);
148}
149
150
151inline char
152__rw_atomic_exchange (char &__x, char __y, bool)
153{
154 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
155 return __sync_lock_test_and_set (&__x, __y);
156}
157
158
159inline signed char
160__rw_atomic_exchange (signed char &__x, signed char __y, bool)
161{
162 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
163 return __sync_lock_test_and_set (&__x, __y);
164}
165
166
167inline unsigned char
168__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
169{
170 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
171 return __sync_lock_test_and_set (&__x, __y);
172}
173
174
175inline short
176__rw_atomic_exchange (short &__x, short __y, bool)
177{
178 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
179 return __sync_lock_test_and_set (&__x, __y);
180}
181
182
183inline unsigned short
184__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
185{
186 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
187 return __sync_lock_test_and_set (&__x, __y);
188}
189
190
191inline int
192__rw_atomic_exchange (int &__x, int __y, bool)
193{
194 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
195 return __sync_lock_test_and_set (&__x, __y);
196}
197
198
199inline unsigned int
200__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
201{
202 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
203 return __sync_lock_test_and_set (&__x, __y);
204}
205
206
207#if defined (__ia64) || defined (__x86_64)
208# if 4 < _RWSTD_LONG_SIZE
209
210inline long
211__rw_atomic_preincrement (long &__x, bool)
212{
213 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
214 return __sync_add_and_fetch (&__x, 1);
215}
216
217
218inline unsigned long
219__rw_atomic_preincrement (unsigned long &__x, bool)
220{
221 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
222 return __sync_add_and_fetch (&__x, 1);
223}
224
225
226inline long
227__rw_atomic_predecrement (long &__x, bool)
228{
229 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
230 return __sync_sub_and_fetch (&__x, 1);
231}
232
233
234inline unsigned long
235__rw_atomic_predecrement (unsigned long &__x, bool)
236{
237 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
238 return __sync_sub_and_fetch (&__x, 1);
239}
240
241
242inline long
243__rw_atomic_exchange (long &__x, long __y, bool)
244{
245 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
246 return __sync_lock_test_and_set (&__x, __y);
247}
248
249
250inline unsigned long
251__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
252{
253 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
254 return __sync_lock_test_and_set (&__x, __y);
255}
256
257# else
258# define _RWSTD_NO_LONG_ATOMIC_OPS
259# endif // 4 < _RWSTD_LONG_SIZE
260
261
262# if defined (_RWSTD_LONG_LONG) && (_RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE)
263
264inline _RWSTD_LONG_LONG
265__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
266{
268 return __sync_add_and_fetch (&__x, 1);
269}
270
271
272inline unsigned _RWSTD_LONG_LONG
273__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
274{
275 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
276 return __sync_add_and_fetch (&__x, 1);
277}
278
279
280inline _RWSTD_LONG_LONG
281__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
282{
284 return __sync_sub_and_fetch (&__x, 1);
285}
286
287
288inline unsigned _RWSTD_LONG_LONG
289__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
290{
291 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
292 return __sync_sub_and_fetch (&__x, 1);
293}
294
295
296inline _RWSTD_LONG_LONG
297__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
298{
300 return __sync_lock_test_and_set (&__x, __y);
301}
302
303
304inline unsigned _RWSTD_LONG_LONG
305__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
306 unsigned _RWSTD_LONG_LONG __y, bool)
307{
308 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
309 return __sync_lock_test_and_set (&__x, __y);
310}
311
312# else
313# define _RWSTD_NO_LLONG_ATOMIC_OPS
314# endif // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
315
316#else // !__ia64 && !__x86_64
317# define _RWSTD_NO_LONG_ATOMIC_OPS
318# define _RWSTD_NO_LLONG_ATOMIC_OPS
319#endif // __ia64 || __x86_64
320
321} // namespace __rw
#define _RWSTD_LONG_LONG
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_COMPILE_ASSERT(const_expr)