Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_atomic-x64.h
Go to the documentation of this file.
1
33#ifdef _MSC_VER
34extern "C" long __cdecl _InterlockedIncrement (volatile long*);
35extern "C" long __cdecl _InterlockedDecrement (volatile long*);
36extern "C" long __cdecl _InterlockedExchange (volatile long*, long);
37# ifdef _RWSTD_MSVC
38# pragma intrinsic (_InterlockedIncrement)
39# pragma intrinsic (_InterlockedDecrement)
40# pragma intrinsic (_InterlockedExchange)
41# endif // _RWSTD_MSVC
42
43# if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
44extern "C" short __cdecl _InterlockedIncrement16 (volatile short*);
45extern "C" short __cdecl _InterlockedDecrement16 (volatile short*);
46# pragma intrinsic (_InterlockedIncrement16)
47# pragma intrinsic (_InterlockedDecrement16)
48# endif // _RWSTD_MSVC >= 1400
49
50# ifdef _M_X64
51extern "C" long long __cdecl _InterlockedIncrement64 (volatile long long*);
52extern "C" long long __cdecl _InterlockedDecrement64 (volatile long long*);
53extern "C" long long __cdecl _InterlockedExchange64 (volatile long long*,
54 long long);
55# ifdef _RWSTD_MSVC
56# pragma intrinsic (_InterlockedIncrement64)
57# pragma intrinsic (_InterlockedDecrement64)
58# pragma intrinsic (_InterlockedExchange64)
59# endif // _RWSTD_MSVC
60# endif // _M_X64
61#endif // _MSC_VER
62
63
65
66extern "C" {
67
68_RWSTD_EXPORT _RWSTD_INT8_T
69__rw_atomic_xchg8 (_RWSTD_INT8_T*, _RWSTD_INT8_T);
70
71_RWSTD_EXPORT _RWSTD_INT16_T
72__rw_atomic_xchg16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
73
74_RWSTD_EXPORT _RWSTD_INT32_T
75__rw_atomic_xchg32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
76
77
78_RWSTD_EXPORT _RWSTD_INT8_T
79__rw_atomic_add8 (_RWSTD_INT8_T*, _RWSTD_INT8_T);
80
81_RWSTD_EXPORT _RWSTD_INT16_T
82__rw_atomic_add16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
83
84_RWSTD_EXPORT _RWSTD_INT32_T
85__rw_atomic_add32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
86
87#ifdef _RWSTD_INT64_T
88
89_RWSTD_EXPORT _RWSTD_INT64_T
90__rw_atomic_xchg64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
91
92_RWSTD_EXPORT _RWSTD_INT64_T
93__rw_atomic_add64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
94
95#endif // _RWSTD_INT64_T
96
97} // extern "C"
98
99
100inline char
101__rw_atomic_preincrement (char &__x, bool)
102{
103 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
104
105 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
106 +1);
107}
108
109
110inline signed char
111__rw_atomic_preincrement (signed char &__x, bool)
112{
113 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
114
115 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
116 +1);
117}
118
119
120inline unsigned char
121__rw_atomic_preincrement (unsigned char &__x, bool)
122{
123 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
124
125 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
126 +1);
127}
128
129
130inline short
131__rw_atomic_preincrement (short &__x, bool)
132{
133 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
134
135#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
136 return _InterlockedIncrement16 (&__x);
137#else
138 return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
139 +1);
140#endif
141}
142
143
144inline unsigned short
145__rw_atomic_preincrement (unsigned short &__x, bool)
146{
147 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
148
149#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
150 return _InterlockedIncrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
151#else
152 return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
153 +1);
154#endif
155}
156
157
158inline int
159__rw_atomic_preincrement (int &__x, bool)
160{
161 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
162
163#ifdef _MSC_VER
164 return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
165#else
166 return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
167 +1);
168#endif
169}
170
171
172inline unsigned int
173__rw_atomic_preincrement (unsigned int &__x, bool)
174{
175 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
176
177#ifdef _MSC_VER
178 return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
179#else
180 return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
181 +1);
182#endif
183}
184
185
186inline char
187__rw_atomic_predecrement (char &__x, bool)
188{
189 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
190
191 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
192 -1);
193}
194
195
196inline signed char
197__rw_atomic_predecrement (signed char &__x, bool)
198{
199 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
200
201 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
202 -1);
203}
204
205
206inline unsigned char
207__rw_atomic_predecrement (unsigned char &__x, bool)
208{
209 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
210
211 return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
212 -1);
213}
214
215
216inline short
217__rw_atomic_predecrement (short &__x, bool)
218{
219 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
220
221#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
222 return _InterlockedDecrement16 (&__x);
223#else
224 return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
225 -1);
226#endif
227}
228
229
230inline unsigned short
231__rw_atomic_predecrement (unsigned short &__x, bool)
232{
233 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
234
235#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
236 return _InterlockedDecrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
237#else
238 return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
239 -1);
240#endif
241}
242
243
244inline int
245__rw_atomic_predecrement (int &__x, bool)
246{
247 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
248
249#ifdef _MSC_VER
250 return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
251#else
252 return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
253 -1);
254#endif
255}
256
257
258inline unsigned int
259__rw_atomic_predecrement (unsigned int &__x, bool)
260{
261 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
262
263#ifdef _MSC_VER
264 return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
265#else
266 return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
267 -1);
268#endif
269}
270
271
272inline char
273__rw_atomic_exchange (char &__x, char __y, bool)
274{
275 _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
276
277 return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
278 _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
279}
280
281
282inline signed char
283__rw_atomic_exchange (signed char &__x, signed char __y, bool)
284{
285 _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
286
287 return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
288 _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
289}
290
291
292inline unsigned char
293__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
294{
295 _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
296
297 return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
298 _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
299}
300
301
302inline short
303__rw_atomic_exchange (short &__x, short __y, bool)
304{
305 _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
306
307 return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
308 _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
309}
310
311
312inline unsigned short
313__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
314{
315 _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
316
317 return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
318 _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
319}
320
321
322inline int
323__rw_atomic_exchange (int &__x, int __y, bool)
324{
325 _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
326
327#ifdef _MSC_VER
328 return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
329 _RWSTD_STATIC_CAST (long, __y));
330#else
331 return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
332 _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
333#endif
334}
335
336
337inline unsigned int
338__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
339{
340 _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
341
342#ifdef _MSC_VER
343 return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
344 _RWSTD_STATIC_CAST (long, __y));
345#else
346 return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
347 _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
348#endif
349}
350
351
352#if 4 < _RWSTD_LONG_SIZE
353
354inline long
355__rw_atomic_preincrement (long &__x, bool)
356{
357 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
358
359 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
360 +1);
361}
362
363
364inline unsigned long
365__rw_atomic_preincrement (unsigned long &__x, bool)
366{
367 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
368
369 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
370 +1);
371}
372
373
374inline long
375__rw_atomic_predecrement (long &__x, bool)
376{
377 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
378
379 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
380 -1);
381}
382
383
384inline unsigned long
385__rw_atomic_predecrement (unsigned long &__x, bool)
386{
387 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
388
389 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
390 -1);
391}
392
393
394inline long
395__rw_atomic_exchange (long &__x, long __y, bool)
396{
397 _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
398
399 return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
400 _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
401}
402
403
404inline unsigned long
405__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
406{
407 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
408
409 return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
410 _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
411}
412
413#else
414# define _RWSTD_NO_LONG_ATOMIC_OPS
415#endif // 4 < _RWSTD_LONG_SIZE
416
417
418#if defined (_RWSTD_LONG_LONG) && (_RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE)
419
420inline _RWSTD_LONG_LONG
421__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
422{
424
425#ifdef _MSC_VER
426 return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
427#else
428 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
429 +1);
430#endif
431}
432
433
434inline unsigned _RWSTD_LONG_LONG
435__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
436{
437 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
438
439#ifdef _MSC_VER
440 return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
441#else
442 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
443 +1);
444#endif
445}
446
447
448inline _RWSTD_LONG_LONG
449__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
450{
452
453#ifdef _MSC_VER
454 return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
455#else
456 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
457 -1);
458#endif
459}
460
461
462inline unsigned _RWSTD_LONG_LONG
463__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
464{
465 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
466
467#ifdef _MSC_VER
468 return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
469#else
470 return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
471 -1);
472#endif
473}
474
475
476inline _RWSTD_LONG_LONG
477__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
478{
480
481#ifdef _MSC_VER
482 return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
483 _RWSTD_STATIC_CAST (__int64, __y));
484#else
485 return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
486 _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
487#endif
488}
489
490
491inline unsigned _RWSTD_LONG_LONG
492__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
493 unsigned _RWSTD_LONG_LONG __y, bool)
494{
495 _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
496
497#ifdef _MSC_VER
498 return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
499 _RWSTD_STATIC_CAST (__int64, __y));
500#else
501 return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
502 _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
503#endif
504}
505
506#else
507# define _RWSTD_NO_LLONG_ATOMIC_OPS
508#endif // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
509
510} // namespace __rw
#define _RWSTD_LONG_LONG
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_COMPILE_ASSERT(const_expr)