QtCore/qatomic_generic.h Source File

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>
80 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
81 { return false; }
82 template <typename T>
83 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
84 { return false; }
85 
86 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
87 
88 template <typename T>
89 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
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>
98 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
99 { return false; }
100 template <typename T>
101 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
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 *);
110 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddOrdered(void * volatile *, qptrdiff);
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>
221 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
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>
231 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
232 {
233  return fetchAndStoreOrdered(newValue);
234 }
235 
236 template <typename T>
237 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
238 {
239  return fetchAndStoreOrdered(newValue);
240 }
241 
242 template <typename T>
243 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
244 {
245  return fetchAndStoreOrdered(newValue);
246 }
247 
248 // Fetch and add for pointers
249 
250 template <typename T>
251 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
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>
261 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
262 {
263  return fetchAndAddOrdered(valueToAdd);
264 }
265 
266 template <typename T>
267 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
268 {
269  return fetchAndAddOrdered(valueToAdd);
270 }
271 
272 template <typename T>
273 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
274 {
275  return fetchAndAddOrdered(valueToAdd);
276 }
277 
279 
281 
282 #endif // QATOMIC_GENERIC_H
int fetchAndStoreRelaxed(int newValue)
bool testAndSetRelease(int expectedValue, int newValue)
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:72
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetOrdered(volatile int *, int, int)
Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreOrdered(volatile int *, int)
T * fetchAndAddAcquire(qptrdiff valueToAdd)
T * fetchAndAddOrdered(qptrdiff valueToAdd)
static bool isReferenceCountingNative()
Definition: qatomic_alpha.h:51
int fetchAndAddRelaxed(int valueToAdd)
T * fetchAndStoreAcquire(T *newValue)
T * fetchAndAddRelease(qptrdiff valueToAdd)
int fetchAndAddAcquire(int valueToAdd)
static bool isReferenceCountingWaitFree()
Definition: qatomic_alpha.h:53
T * fetchAndAddRelaxed(qptrdiff valueToAdd)
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:98
bool testAndSetOrdered(T *expectedValue, T *newValue)
bool testAndSetAcquire(int expectedValue, int newValue)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:89
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:58
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:80
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:65
T * fetchAndStoreRelaxed(T *newValue)
static bool isFetchAndAddWaitFree()
bool testAndSetRelaxed(int expectedValue, int newValue)
volatile long _q_value
Definition: qbasicatomic.h:61
Q_CORE_EXPORT void * QBasicAtomicPointer_fetchAndAddOrdered(void *volatile *, qptrdiff)
T * fetchAndStoreRelease(T *newValue)
bool testAndSetRelease(T *expectedValue, T *newValue)
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:92
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:60
Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetOrdered(void *volatile *, void *, void *)
bool testAndSetAcquire(T *expectedValue, T *newValue)
static bool isFetchAndAddWaitFree()
Definition: qatomic_alpha.h:74
T * fetchAndStoreOrdered(T *newValue)
Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddOrdered(volatile int *, int)
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:67
bool testAndSetRelaxed(T *expectedValue, T *newValue)
int fetchAndStoreAcquire(int newValue)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
bool testAndSetOrdered(int expectedValue, int newValue)
#define QT_END_HEADER
Definition: qglobal.h:142
Q_CORE_EXPORT void * QBasicAtomicPointer_fetchAndStoreOrdered(void *volatile *, void *)
int fetchAndAddOrdered(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
int fetchAndAddRelease(int valueToAdd)
int fetchAndStoreRelease(int newValue)
GLsizei const GLvoid * pointer
Definition: GLee.h:1361