Qt 4.8
qatomic_i386.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QATOMIC_I386_H
43 #define QATOMIC_I386_H
44 
47 
48 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
49 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_WAIT_FREE
50 
52 { return true; }
54 { return true; }
55 
56 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
57 #define Q_ATOMIC_INT_TEST_AND_SET_IS_WAIT_FREE
58 
60 { return true; }
62 { return true; }
63 
64 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
65 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_WAIT_FREE
66 
68 { return true; }
70 { return true; }
71 
72 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
73 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_WAIT_FREE
74 
76 { return true; }
78 { return true; }
79 
80 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
81 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_WAIT_FREE
82 
83 template <typename T>
85 { return true; }
86 template <typename T>
88 { return true; }
89 
90 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
91 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_WAIT_FREE
92 
93 template <typename T>
95 { return true; }
96 template <typename T>
98 { return true; }
99 
100 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
101 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_WAIT_FREE
102 
103 template <typename T>
105 { return true; }
106 template <typename T>
108 { return true; }
109 
110 #if defined(Q_CC_GNU) || defined(Q_CC_INTEL)
111 
112 inline bool QBasicAtomicInt::ref()
113 {
114  unsigned char ret;
115  asm volatile("lock\n"
116  "incl %0\n"
117  "setne %1"
118  : "=m" (_q_value), "=qm" (ret)
119  : "m" (_q_value)
120  : "memory");
121  return ret != 0;
122 }
123 
124 inline bool QBasicAtomicInt::deref()
125 {
126  unsigned char ret;
127  asm volatile("lock\n"
128  "decl %0\n"
129  "setne %1"
130  : "=m" (_q_value), "=qm" (ret)
131  : "m" (_q_value)
132  : "memory");
133  return ret != 0;
134 }
135 
136 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
137 {
138  unsigned char ret;
139  asm volatile("lock\n"
140  "cmpxchgl %3,%2\n"
141  "sete %1\n"
142  : "=a" (newValue), "=qm" (ret), "+m" (_q_value)
143  : "r" (newValue), "0" (expectedValue)
144  : "memory");
145  return ret != 0;
146 }
147 
148 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
149 {
150  asm volatile("xchgl %0,%1"
151  : "=r" (newValue), "+m" (_q_value)
152  : "0" (newValue)
153  : "memory");
154  return newValue;
155 }
156 
157 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
158 {
159  asm volatile("lock\n"
160  "xaddl %0,%1"
161  : "=r" (valueToAdd), "+m" (_q_value)
162  : "0" (valueToAdd)
163  : "memory");
164  return valueToAdd;
165 }
166 
167 template <typename T>
168 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
169 {
170  unsigned char ret;
171  asm volatile("lock\n"
172  "cmpxchgl %3,%2\n"
173  "sete %1\n"
174  : "=a" (newValue), "=qm" (ret), "+m" (_q_value)
175  : "r" (newValue), "0" (expectedValue)
176  : "memory");
177  return ret != 0;
178 }
179 
180 template <typename T>
182 {
183  asm volatile("xchgl %0,%1"
184  : "=r" (newValue), "+m" (_q_value)
185  : "0" (newValue)
186  : "memory");
187  return newValue;
188 }
189 
190 template <typename T>
192 {
193  asm volatile("lock\n"
194  "xaddl %0,%1"
195  : "=r" (valueToAdd), "+m" (_q_value)
196  : "0" (valueToAdd * sizeof(T))
197  : "memory");
198  return reinterpret_cast<T *>(valueToAdd);
199 }
200 
201 #else
202 
203 extern "C" {
204  Q_CORE_EXPORT int q_atomic_test_and_set_int(volatile int *ptr, int expected, int newval);
205  Q_CORE_EXPORT int q_atomic_test_and_set_ptr(volatile void *ptr, const void *expected, const void *newval);
206  Q_CORE_EXPORT int q_atomic_increment(volatile int *ptr);
207  Q_CORE_EXPORT int q_atomic_decrement(volatile int *ptr);
208  Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval);
209  Q_CORE_EXPORT void *q_atomic_set_ptr(volatile void *ptr, void *newval);
210  Q_CORE_EXPORT int q_atomic_fetch_and_add_int(volatile int *ptr, int value);
211  Q_CORE_EXPORT void *q_atomic_fetch_and_add_ptr(volatile void *ptr, int value);
212 } // extern "C"
213 
214 inline bool QBasicAtomicInt::ref()
215 {
216  return q_atomic_increment(&_q_value) != 0;
217 }
218 
219 inline bool QBasicAtomicInt::deref()
220 {
221  return q_atomic_decrement(&_q_value) != 0;
222 }
223 
224 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
225 {
226  return q_atomic_test_and_set_int(&_q_value, expectedValue, newValue) != 0;
227 }
228 
229 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
230 {
231  return q_atomic_set_int(&_q_value, newValue);
232 }
233 
234 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
235 {
236  return q_atomic_fetch_and_add_int(&_q_value, valueToAdd);
237 }
238 
239 template <typename T>
240 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
241 {
242  return q_atomic_test_and_set_ptr(&_q_value, expectedValue, newValue);
243 }
244 
245 template <typename T>
247 {
248  return reinterpret_cast<T *>(q_atomic_set_ptr(&_q_value, newValue));
249 }
250 
251 template <typename T>
253 {
254  return reinterpret_cast<T *>(q_atomic_fetch_and_add_ptr(&_q_value, valueToAdd * sizeof(T)));
255 }
256 
257 #endif
258 
259 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
260 {
261  return testAndSetOrdered(expectedValue, newValue);
262 }
263 
264 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
265 {
266  return testAndSetOrdered(expectedValue, newValue);
267 }
268 
269 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
270 {
271  return testAndSetOrdered(expectedValue, newValue);
272 }
273 
274 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
275 {
276  return fetchAndStoreOrdered(newValue);
277 }
278 
279 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
280 {
281  return fetchAndStoreOrdered(newValue);
282 }
283 
284 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
285 {
286  return fetchAndStoreOrdered(newValue);
287 }
288 
289 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
290 {
291  return fetchAndAddOrdered(valueToAdd);
292 }
293 
294 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
295 {
296  return fetchAndAddOrdered(valueToAdd);
297 }
298 
299 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
300 {
301  return fetchAndAddOrdered(valueToAdd);
302 }
303 
304 template <typename T>
305 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
306 {
307  return testAndSetOrdered(expectedValue, newValue);
308 }
309 
310 template <typename T>
311 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
312 {
313  return testAndSetOrdered(expectedValue, newValue);
314 }
315 
316 template <typename T>
317 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
318 {
319  return testAndSetOrdered(expectedValue, newValue);
320 }
321 
322 template <typename T>
324 {
325  return fetchAndStoreOrdered(newValue);
326 }
327 
328 template <typename T>
330 {
331  return fetchAndStoreOrdered(newValue);
332 }
333 
334 template <typename T>
336 {
337  return fetchAndStoreOrdered(newValue);
338 }
339 
340 template <typename T>
342 {
343  return fetchAndAddOrdered(valueToAdd);
344 }
345 
346 template <typename T>
348 {
349  return fetchAndAddOrdered(valueToAdd);
350 }
351 
352 template <typename T>
354 {
355  return fetchAndAddOrdered(valueToAdd);
356 }
357 
360 
361 #endif // QATOMIC_I386_H
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:65
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:58
int fetchAndStoreRelease(int newValue)
static bool isReferenceCountingNative()
Definition: qatomic_alpha.h:51
T * fetchAndAddRelaxed(qptrdiff valueToAdd)
volatile int _q_value
Definition: qbasicatomic.h:64
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:98
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:80
Q_CORE_EXPORT int q_atomic_increment(volatile int *ptr)
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:72
T * fetchAndStoreRelease(T *newValue)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
Q_CORE_EXPORT int q_atomic_test_and_set_int(volatile int *ptr, int expected, int newval)
Q_CORE_EXPORT void * q_atomic_fetch_and_add_ptr(volatile void *ptr, int value)
T * fetchAndAddRelease(qptrdiff valueToAdd)
bool testAndSetOrdered(T *expectedValue, T *newValue)
int fetchAndAddAcquire(int valueToAdd)
T * fetchAndAddAcquire(qptrdiff valueToAdd)
int fetchAndStoreRelaxed(int newValue)
T * fetchAndAddOrdered(qptrdiff valueToAdd)
bool testAndSetAcquire(int expectedValue, int newValue)
Q_CORE_EXPORT int q_atomic_fetch_and_add_int(volatile int *ptr, int value)
bool testAndSetRelaxed(int expectedValue, int newValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_CORE_EXPORT int q_atomic_test_and_set_ptr(volatile void *ptr, const void *expected, const void *newval)
int fetchAndStoreAcquire(int newValue)
QIntegerForSizeof< void * >::Signed qptrdiff
Definition: qglobal.h:987
T * fetchAndStoreOrdered(T *newValue)
Q_CORE_EXPORT int q_atomic_decrement(volatile int *ptr)
#define Q_INLINE_TEMPLATE
Definition: qglobal.h:1713
int fetchAndAddRelease(int valueToAdd)
const T * ptr(const T &t)
bool testAndSetOrdered(int expectedValue, int newValue)
T * fetchAndStoreAcquire(T *newValue)
Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval)
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:67
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:60
static bool isReferenceCountingWaitFree()
Definition: qatomic_alpha.h:53
int fetchAndAddOrdered(int valueToAdd)
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:92
static bool isFetchAndAddWaitFree()
Definition: qatomic_alpha.h:74
static bool isFetchAndAddWaitFree()
bool testAndSetRelease(int expectedValue, int newValue)
Q_CORE_EXPORT void * q_atomic_set_ptr(volatile void *ptr, void *newval)
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
int fetchAndAddRelaxed(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
bool testAndSetRelaxed(T *expectedValue, T *newValue)
bool testAndSetRelease(T *expectedValue, T *newValue)
#define QT_END_HEADER
Definition: qglobal.h:137
T * fetchAndStoreRelaxed(T *newValue)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:89
bool testAndSetAcquire(T *expectedValue, T *newValue)