Qt 4.8
qatomic_vxworks.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 qmake spec 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_VXWORKS_H
43 #define QATOMIC_VXWORKS_H
44 
46 
47 #if defined(__ppc)
48 # include <QtCore/qatomic_powerpc.h>
49 #else // generic implementation with taskLock()
50 
51 #if 0
52 // we don't want to include the system header here for two function prototypes,
53 // because it pulls in a _lot_ of stuff that pollutes the global namespace
54 # include <vxWorksCommon.h>
55 # include <taskLib.h>
56 #else
57 #if defined(_WRS_KERNEL)
58 extern "C" int taskLock();
59 extern "C" int taskUnlock();
60 #else
61 inline int taskLock() { return 0; }
62 inline int taskUnlock() { return 0; }
63 #endif
64 #endif
65 
66 
67 
69 
70 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
71 
73 { return false; }
75 { return false; }
76 
77 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
78 
80 { return false; }
82 { return false; }
83 
84 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
85 
87 { return false; }
89 { return false; }
90 
91 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
92 
94 { return false; }
96 { return false; }
97 
98 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
99 
100 template <typename T>
102 { return false; }
103 template <typename T>
105 { return false; }
106 
107 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
108 
109 template <typename T>
111 { return false; }
112 template <typename T>
114 { return false; }
115 
116 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
117 
118 template <typename T>
120 { return false; }
121 template <typename T>
123 { return false; }
124 
125 // Reference counting
126 
127 inline bool QBasicAtomicInt::ref()
128 {
129  taskLock();
130  bool ret = (++_q_value != 0);
131  taskUnlock();
132  return ret;
133 }
134 
135 inline bool QBasicAtomicInt::deref()
136 {
137  taskLock();
138  bool ret = (--_q_value != 0);
139  taskUnlock();
140  return ret;
141 }
142 
143 // Test-and-set for integers
144 
145 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
146 {
147  taskLock();
148  if (_q_value == expectedValue) {
149  _q_value = newValue;
150  taskUnlock();
151  return true;
152  }
153  taskUnlock();
154  return false;
155 }
156 
157 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
158 {
159  return testAndSetOrdered(expectedValue, newValue);
160 }
161 
162 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
163 {
164  return testAndSetOrdered(expectedValue, newValue);
165 }
166 
167 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
168 {
169  return testAndSetOrdered(expectedValue, newValue);
170 }
171 
172 // Fetch-and-store for integers
173 
174 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
175 {
176  taskLock();
177  int returnValue = _q_value;
178  _q_value = newValue;
179  taskUnlock();
180  return returnValue;
181 }
182 
183 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
184 {
185  return fetchAndStoreOrdered(newValue);
186 }
187 
188 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
189 {
190  return fetchAndStoreOrdered(newValue);
191 }
192 
193 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
194 {
195  return fetchAndStoreOrdered(newValue);
196 }
197 
198 // Fetch-and-add for integers
199 
200 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
201 {
202  taskLock();
203  int originalValue = _q_value;
204  _q_value += valueToAdd;
205  taskUnlock();
206  return originalValue;
207 }
208 
209 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
210 {
211  return fetchAndAddOrdered(valueToAdd);
212 }
213 
214 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
215 {
216  return fetchAndAddOrdered(valueToAdd);
217 }
218 
219 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
220 {
221  return fetchAndAddOrdered(valueToAdd);
222 }
223 
224 // Test and set for pointers
225 
226 template <typename T>
227 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
228 {
229  taskLock();
230  if (_q_value == expectedValue) {
231  _q_value = newValue;
232  taskUnlock();
233  return true;
234  }
235  taskUnlock();
236  return false;
237 }
238 
239 template <typename T>
240 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
241 {
242  return testAndSetOrdered(expectedValue, newValue);
243 }
244 
245 template <typename T>
246 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
247 {
248  return testAndSetOrdered(expectedValue, newValue);
249 }
250 
251 template <typename T>
252 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
253 {
254  return testAndSetOrdered(expectedValue, newValue);
255 }
256 
257 // Fetch and store for pointers
258 
259 template <typename T>
261 {
262  taskLock();
263  T *returnValue = (_q_value);
264  _q_value = newValue;
265  taskUnlock();
266  return returnValue;
267 }
268 
269 template <typename T>
271 {
272  return fetchAndStoreOrdered(newValue);
273 }
274 
275 template <typename T>
277 {
278  return fetchAndStoreOrdered(newValue);
279 }
280 
281 template <typename T>
283 {
284  return fetchAndStoreOrdered(newValue);
285 }
286 
287 // Fetch and add for pointers
288 
289 template <typename T>
291 {
292  taskLock();
293  T *returnValue = (_q_value);
294  _q_value += valueToAdd;
295  taskUnlock();
296  return returnValue;
297 }
298 
299 template <typename T>
301 {
302  return fetchAndAddOrdered(valueToAdd);
303 }
304 
305 template <typename T>
307 {
308  return fetchAndAddOrdered(valueToAdd);
309 }
310 
311 template <typename T>
313 {
314  return fetchAndAddOrdered(valueToAdd);
315 }
316 
318 
319 #endif // generic implementation with taskLock()
320 
322 
323 #endif // QATOMIC_VXWORKS_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
int taskUnlock()
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
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)
int fetchAndAddRelaxed(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
bool testAndSetRelaxed(T *expectedValue, T *newValue)
bool testAndSetRelease(T *expectedValue, T *newValue)
int taskLock()
#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)