Qt 4.8
qatomic_integrity.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 QtGui 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_INTEGRITY_H
43 #define QATOMIC_INTEGRITY_H
44 
45 #include <INTEGRITY.h>
46 
48 
50 
51 #define qt_pp2addrp(a) reinterpret_cast<Address *>(const_cast<T **>(a))
52 #define qt_ip2addrp(a) reinterpret_cast<Address *>(const_cast<int *>(a))
53 #define qt_p2addrp(a) reinterpret_cast<Address *>(a)
54 #define qt_addr(a) reinterpret_cast<Address>(a)
55 
56 
57 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
58 
60 { return true; }
61 
62 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_WAIT_FREE
63 
65 { return true; }
66 
67 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
68 
70 { return true; }
71 
72 #define Q_ATOMIC_INT_TEST_AND_SET_IS_WAIT_FREE
73 
75 { return true; }
76 
77 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
78 
80 { return true; }
81 
82 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_WAIT_FREE
83 
85 { return true; }
86 
87 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
88 
90 { return true; }
91 
92 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_WAIT_FREE
93 
95 { return true; }
96 
97 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
98 
99 template <typename T>
101 { return true; }
102 
103 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_WAIT_FREE
104 
105 template <typename T>
107 { return true; }
108 
109 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
110 
111 template <typename T>
113 { return true; }
114 
115 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_WAIT_FREE
116 
117 template <typename T>
119 { return true; }
120 
121 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
122 
123 template <typename T>
125 { return true; }
126 
127 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_WAIT_FREE
128 
129 template <typename T>
131 { return true; }
132 
133 // Reference counting
134 
135 inline bool QBasicAtomicInt::ref()
136 {
137  int old_value;
138  AtomicModify(qt_ip2addrp(&_q_value), qt_ip2addrp(&old_value), 0, 1U);
139  return _q_value != 0;
140 }
141 
142 inline bool QBasicAtomicInt::deref()
143 {
144  int old_value;
145  AtomicModify(qt_ip2addrp(&_q_value), qt_ip2addrp(&old_value), 0, -1U);
146  return _q_value != 0;
147 }
148 
149 // Test and set for integers
150 
151 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
152 {
153  return TestAndSet(qt_ip2addrp(&_q_value), expectedValue, newValue) == Success;
154 }
155 
156 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
157 {
158  return testAndSetOrdered(expectedValue, newValue);
159 }
160 
161 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
162 {
163  return testAndSetOrdered(expectedValue, newValue);
164 }
165 
166 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
167 {
168  return testAndSetOrdered(expectedValue, newValue);
169 }
170 
171 // Fetch and store for integers
172 
173 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
174 {
175  int old_value;
176  do {
177  old_value = _q_value;
178  } while (TestAndSet(qt_ip2addrp(&_q_value), old_value, newValue) != Success);
179  return old_value;
180 }
181 
182 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
183 {
184  return fetchAndStoreOrdered(newValue);
185 }
186 
187 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
188 {
189  return fetchAndStoreOrdered(newValue);
190 }
191 
192 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
193 {
194  return fetchAndStoreOrdered(newValue);
195 }
196 
197 // Fetch and add for integers
198 
199 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
200 {
201  int old_value;
202  AtomicModify(qt_ip2addrp(&_q_value), qt_ip2addrp(&old_value), 0, valueToAdd);
203 
204  return old_value;
205 }
206 
207 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
208 {
209  return fetchAndAddOrdered(valueToAdd);
210 }
211 
212 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
213 {
214  return fetchAndAddOrdered(valueToAdd);
215 }
216 
217 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
218 {
219  return fetchAndAddOrdered(valueToAdd);
220 }
221 
222 // Test and set for pointers
223 
224 template <typename T>
225 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
226 {
227  return TestAndSet(qt_pp2addrp(&_q_value), qt_addr(expectedValue), qt_addr(newValue)) == Success;
228 }
229 
230 template <typename T>
231 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
232 {
233  return testAndSetOrdered(expectedValue, newValue);
234 }
235 
236 template <typename T>
237 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
238 {
239  return testAndSetOrdered(expectedValue, newValue);
240 }
241 
242 template <typename T>
243 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
244 {
245  return testAndSetOrdered(expectedValue, newValue);
246 }
247 
248 // Fetch and store for pointers
249 
250 template <typename T>
252 {
253  Address old_value;
254 
255  do {
256  old_value = qt_addr(_q_value);
257  } while (TestAndSet(qt_pp2addrp(&_q_value), old_value, qt_addr(newValue)) != Success);
258 
259  return reinterpret_cast<T *>(old_value);
260 }
261 
262 template <typename T>
264 {
265  return fetchAndStoreOrdered(newValue);
266 }
267 
268 template <typename T>
270 {
271  return fetchAndStoreOrdered(newValue);
272 }
273 
274 template <typename T>
276 {
277  return fetchAndStoreOrdered(newValue);
278 }
279 
280 // Fetch and add for pointers
281 
282 template <typename T>
284 {
285  Address old_value;
286  AtomicModify(qt_pp2addrp(&_q_value), &old_value, 0, valueToAdd * sizeof(T));
287 
288  return reinterpret_cast<T *>(old_value);
289 }
290 
291 template <typename T>
293 {
294  return fetchAndAddOrdered(valueToAdd);
295 }
296 
297 template <typename T>
299 {
300  return fetchAndAddOrdered(valueToAdd);
301 }
302 
303 template <typename T>
305 {
306  return fetchAndAddOrdered(valueToAdd);
307 }
308 
310 
312 
313 #endif // QATOMIC_INTEGRITY_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
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:72
T * fetchAndStoreRelease(T *newValue)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
#define qt_ip2addrp(a)
T * fetchAndAddRelease(qptrdiff valueToAdd)
#define qt_addr(a)
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)
bool testAndSetRelaxed(int expectedValue, int newValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int fetchAndStoreAcquire(int newValue)
QIntegerForSizeof< void * >::Signed qptrdiff
Definition: qglobal.h:987
T * fetchAndStoreOrdered(T *newValue)
#define Q_INLINE_TEMPLATE
Definition: qglobal.h:1713
int fetchAndAddRelease(int valueToAdd)
bool testAndSetOrdered(int expectedValue, int newValue)
T * fetchAndStoreAcquire(T *newValue)
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)
#define qt_pp2addrp(a)
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)