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