Qt 4.8
qatomic_generic.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_GENERIC_H
43 #define QATOMIC_GENERIC_H
44 
46 
48 
49 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
50 
52 { return false; }
54 { return false; }
55 
56 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
57 
59 { return false; }
61 { return false; }
62 
63 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
64 
66 { return false; }
68 { return false; }
69 
70 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
71 
73 { return false; }
75 { return false; }
76 
77 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
78 
79 template <typename T>
81 { return false; }
82 template <typename T>
84 { return false; }
85 
86 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
87 
88 template <typename T>
90 { return false; }
91 template <typename T>
93 { return false; }
94 
95 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
96 
97 template <typename T>
99 { return false; }
100 template <typename T>
102 { return false; }
103 
104 Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetOrdered(volatile int *, int, int);
105 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreOrdered(volatile int *, int);
106 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddOrdered(volatile int *, int);
107 
108 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetOrdered(void * volatile *, void *, void *);
109 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreOrdered(void * volatile *, void *);
111 
112 // Reference counting
113 
114 inline bool QBasicAtomicInt::ref()
115 {
117 }
118 
119 inline bool QBasicAtomicInt::deref()
120 {
122 }
123 
124 // Test and set for integers
125 
126 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
127 {
128  return QBasicAtomicInt_testAndSetOrdered(&_q_value, expectedValue, newValue);
129 }
130 
131 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
132 {
133  return testAndSetOrdered(expectedValue, newValue);
134 }
135 
136 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
137 {
138  return testAndSetOrdered(expectedValue, newValue);
139 }
140 
141 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
142 {
143  return testAndSetOrdered(expectedValue, newValue);
144 }
145 
146 // Fetch and store for integers
147 
148 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
149 {
151 }
152 
153 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
154 {
155  return fetchAndStoreOrdered(newValue);
156 }
157 
158 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
159 {
160  return fetchAndStoreOrdered(newValue);
161 }
162 
163 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
164 {
165  return fetchAndStoreOrdered(newValue);
166 }
167 
168 // Fetch and add for integers
169 
170 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
171 {
172  return QBasicAtomicInt_fetchAndAddOrdered(&_q_value, valueToAdd);
173 }
174 
175 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
176 {
177  return fetchAndAddOrdered(valueToAdd);
178 }
179 
180 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
181 {
182  return fetchAndAddOrdered(valueToAdd);
183 }
184 
185 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
186 {
187  return fetchAndAddOrdered(valueToAdd);
188 }
189 
190 // Test and set for pointers
191 
192 template <typename T>
193 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
194 {
195  union { T * volatile * typed; void * volatile * voidp; } pointer;
196  pointer.typed = &_q_value;
197  return QBasicAtomicPointer_testAndSetOrdered(pointer.voidp, expectedValue, newValue);
198 }
199 
200 template <typename T>
201 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
202 {
203  return testAndSetOrdered(expectedValue, newValue);
204 }
205 
206 template <typename T>
207 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
208 {
209  return testAndSetOrdered(expectedValue, newValue);
210 }
211 
212 template <typename T>
213 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
214 {
215  return testAndSetOrdered(expectedValue, newValue);
216 }
217 
218 // Fetch and store for pointers
219 
220 template <typename T>
222 {
223  union { T * volatile * typed; void * volatile * voidp; } pointer;
224  union { T *typed; void *voidp; } returnValue;
225  pointer.typed = &_q_value;
226  returnValue.voidp = QBasicAtomicPointer_fetchAndStoreOrdered(pointer.voidp, newValue);
227  return returnValue.typed;
228 }
229 
230 template <typename T>
232 {
233  return fetchAndStoreOrdered(newValue);
234 }
235 
236 template <typename T>
238 {
239  return fetchAndStoreOrdered(newValue);
240 }
241 
242 template <typename T>
244 {
245  return fetchAndStoreOrdered(newValue);
246 }
247 
248 // Fetch and add for pointers
249 
250 template <typename T>
252 {
253  union { T * volatile *typed; void * volatile *voidp; } pointer;
254  union { T *typed; void *voidp; } returnValue;
255  pointer.typed = &_q_value;
256  returnValue.voidp = QBasicAtomicPointer_fetchAndAddOrdered(pointer.voidp, valueToAdd * sizeof(T));
257  return returnValue.typed;
258 }
259 
260 template <typename T>
262 {
263  return fetchAndAddOrdered(valueToAdd);
264 }
265 
266 template <typename T>
268 {
269  return fetchAndAddOrdered(valueToAdd);
270 }
271 
272 template <typename T>
274 {
275  return fetchAndAddOrdered(valueToAdd);
276 }
277 
279 
281 
282 #endif // QATOMIC_GENERIC_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 bool QBasicAtomicInt_testAndSetOrdered(volatile int *, int, int)
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:72
T * fetchAndStoreRelease(T *newValue)
Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreOrdered(volatile int *, int)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
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)
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
Q_CORE_EXPORT void * QBasicAtomicPointer_fetchAndAddOrdered(void *volatile *, qptrdiff)
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)
Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetOrdered(void *volatile *, void *, void *)
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
int fetchAndAddRelaxed(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
bool testAndSetRelaxed(T *expectedValue, T *newValue)
Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddOrdered(volatile int *, int)
bool testAndSetRelease(T *expectedValue, T *newValue)
#define QT_END_HEADER
Definition: qglobal.h:137
Q_CORE_EXPORT void * QBasicAtomicPointer_fetchAndStoreOrdered(void *volatile *, void *)
T * fetchAndStoreRelaxed(T *newValue)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:89
bool testAndSetAcquire(T *expectedValue, T *newValue)