Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_atomic.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_RW_ATOMIC_H_INCLUDED
33#define _RWSTD_RW_ATOMIC_H_INCLUDED
34
35
36#if __GNUG__ >= 3
37# pragma GCC system_header
38#endif // gcc >= 3
39
40
41#ifndef _RWSTD_RW_DEFS_H_INCLUDED
42# include <rw/_defs.h>
43#endif // _RWSTD_RW_DEFS_H_INCLUDED
44
45
46#ifdef _RWSTD_REENTRANT
47
48# if defined (_RWSTD_NO_ATOMIC_OPS)
49 // do nothing
50# elif defined (__DECCXX)
51# include <rw/_atomic-deccxx.h>
52# elif defined (__sparc) && (defined (__SUNPRO_CC) || defined (__GNUG__))
53# include <rw/_atomic-sparc.h>
54# elif defined (_AIX43) && defined (__IBMCPP__)
55# include <rw/_atomic-xlc.h>
56# elif defined (__sgi) && defined (__host_mips)
57# include <rw/_atomic-mipspro.h>
58# elif defined (_PA_RISC2_0)
59# include <rw/_atomic-parisc.h>
60# elif defined (__GNUG__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401) \
61 && (defined (__i486__) || defined (__x86_64) || defined (__ia64)) \
62 && !defined (__INTEL_COMPILER) \
63 || (defined (__INTEL_COMPILER) && defined (__ia64))
64# include <rw/_atomic-sync.h>
65# elif defined (__i386__) && (defined (__GNUG__) \
66 || defined (__INTEL_COMPILER)) || defined (_M_IX86)
67# include <rw/_atomic-x86.h>
68# elif defined (__ia64) || defined (__x86_64) || defined (_M_X64)
69# include <rw/_atomic-x64.h>
70# else
71# define _RWSTD_NO_ATOMIC_OPS
72# endif
73
74# ifndef _RWSTD_NO_ATOMIC_OPS
75
76
78# ifndef _RWSTD_NO_BOOL
79
80# if _RWSTD_BOOL_SIZE == _RWSTD_CHAR_SIZE \
81 && !defined (_RWSTD_NO_CHAR_ATOMIC_OPS)
82# define _RWSTD_BOOL_TYPE char
83# elif _RWSTD_BOOL_SIZE == _RWSTD_SHORT_SIZE \
84 && !defined (_RWSTD_NO_SHORT_ATOMIC_OPS)
85# define _RWSTD_BOOL_TYPE short
86# elif _RWSTD_BOOL_SIZE == _RWSTD_INT_SIZE \
87 && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
88# define _RWSTD_BOOL_TYPE int
89# endif
90
91# ifdef _RWSTD_BOOL_TYPE
92
94
95inline bool
96__rw_atomic_exchange (bool &__x, bool __y, bool)
97{
98 return 0 != __rw_atomic_exchange (
99 _RWSTD_REINTERPRET_CAST (_RWSTD_BOOL_TYPE&, __x),
100 _RWSTD_STATIC_CAST (_RWSTD_BOOL_TYPE, __y),
101 false);
102}
103
104} // namespace __rw
105
106# undef _RWSTD_BOOL_TYPE
107# endif // _RWSTD_BOOL_TYPE
108
109# endif // _RWSTD_NO_BOOL
110
111
112
114# if _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE \
115 && defined (_RWSTD_NO_LONG_ATOMIC_OPS) \
116 && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
117
118# undef _RWSTD_NO_LONG_ATOMIC_OPS
119
120# if 6 == _RWSTD_HP_aCC_MAJOR
121 // suppress HP aCC 64 bit migration remark: conversion from
122 // "long *" to "int *" may cause target of pointers to have
123 // a different size
124# pragma diag_suppress 4230
125# endif // HP aCC 6
126
128
129inline long
130__rw_atomic_preincrement (long &__x, bool)
131{
132 return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
133 false);
134}
135
136inline unsigned long
137__rw_atomic_preincrement (unsigned long &__x, bool)
138{
139 return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
140 false);
141}
142
143inline long
144__rw_atomic_predecrement (long &__x, bool)
145{
146 return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
147 false);
148}
149
150inline unsigned long
151__rw_atomic_predecrement (unsigned long &__x, bool)
152{
153 return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
154 false);
155}
156
157inline long
158__rw_atomic_exchange (long &__x, long __y, bool)
159{
160 return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
161 _RWSTD_STATIC_CAST (int, __y),
162 false);
163}
164
165inline unsigned long
166__rw_atomic_exchange (unsigned long &__x,
167 unsigned long __y, bool)
168{
169 return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
170 _RWSTD_STATIC_CAST (int, __y),
171 false);
172}
173
174} // namespace __rw
175
176# if 6 == _RWSTD_HP_aCC_MAJOR
177# pragma diag_default 4230
178# endif // HP aCC 6
179
180# endif // _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE
181
182
183
185# if defined (_RWSTD_LONG_LONG) \
186 && _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE \
187 && defined (_RWSTD_NO_LLONG_ATOMIC_OPS) \
188 && !defined (_RWSTD_NO_LONG_ATOMIC_OPS)
189
190# undef _RWSTD_NO_LLONG_ATOMIC_OPS
191
193
194inline _RWSTD_LONG_LONG
195__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
196{
197 return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
198 false);
199}
200
201inline unsigned _RWSTD_LONG_LONG
202__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
203{
204 return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
205 false);
206}
207
208inline _RWSTD_LONG_LONG
209__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
210{
211 return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
212 false);
213}
214
215inline unsigned _RWSTD_LONG_LONG
216__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
217{
218 return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
219 false);
220}
221
222inline _RWSTD_LONG_LONG
223__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
224{
225 return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
226 _RWSTD_STATIC_CAST (long, __y),
227 false);
228}
229
230inline unsigned _RWSTD_LONG_LONG
231__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
232 unsigned _RWSTD_LONG_LONG __y, bool)
233{
234 return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
235 _RWSTD_STATIC_CAST (long, __y),
236 false);
237}
238
239} // namespace __rw
240
241# endif // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE
242
243# endif // _RWSTD_NO_ATOMIC_OPS
244
245#else // if !defined (_RWSTD_REENTRANT)
246
248
249// atomic in a single-threaded environment
250template <class _TypeT, class _TypeU>
251inline
252_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
253{
254 _TypeT __tmp = __t;
255 __t = _TypeT (__u);
256 return __tmp;
257}
258
259} // namespace __rw
260
261#endif // _RWSTD_REENTRANT
262
263
265
266// available in all environments (ST and MT), used along with
267// __rw_atomic_exchange<>() from conditional expressions in iostreams
268template <class _TypeT, class _TypeU>
269inline
270_TypeT __rw_ordinary_exchange (_TypeT &__t, const _TypeU &__u)
271{
272 _TypeT __tmp = __t;
273 __t = __u;
274 return __tmp;
275}
276
277} // namespace __rw
278
279
280#endif // _RWSTD_RW_ATOMIC_H_INCLUDED
#define _RWSTD_LONG_LONG
#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