1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake spec of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QATOMIC_VXWORKS_H
43 #define QATOMIC_VXWORKS_H
48 # include <QtCore/qatomic_powerpc.h>
49 #else // generic implementation with taskLock()
51 #include <QtCore/qoldbasicatomic.h>
54 // we don't want to include the system header here for two function prototypes,
55 // because it pulls in a _lot_ of stuff that pollutes the global namespace
56 # include <vxWorksCommon.h>
59 extern "C" int taskLock();
60 extern "C" int taskUnlock();
67 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
69 inline bool QBasicAtomicInt::isReferenceCountingNative()
71 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
74 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
76 inline bool QBasicAtomicInt::isTestAndSetNative()
78 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
81 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
83 inline bool QBasicAtomicInt::isFetchAndStoreNative()
85 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
88 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
90 inline bool QBasicAtomicInt::isFetchAndAddNative()
92 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
95 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
98 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
100 template <typename T>
101 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
104 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
106 template <typename T>
107 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
109 template <typename T>
110 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
113 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
115 template <typename T>
116 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
118 template <typename T>
119 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
122 // Reference counting
124 inline bool QBasicAtomicInt::ref()
127 bool ret = (++_q_value != 0);
132 inline bool QBasicAtomicInt::deref()
135 bool ret = (--_q_value != 0);
140 // Test-and-set for integers
142 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
145 if (_q_value == expectedValue) {
154 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
156 return testAndSetOrdered(expectedValue, newValue);
159 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
161 return testAndSetOrdered(expectedValue, newValue);
164 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
166 return testAndSetOrdered(expectedValue, newValue);
169 // Fetch-and-store for integers
171 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
174 int returnValue = _q_value;
180 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
182 return fetchAndStoreOrdered(newValue);
185 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
187 return fetchAndStoreOrdered(newValue);
190 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
192 return fetchAndStoreOrdered(newValue);
195 // Fetch-and-add for integers
197 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
200 int originalValue = _q_value;
201 _q_value += valueToAdd;
203 return originalValue;
206 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
208 return fetchAndAddOrdered(valueToAdd);
211 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
213 return fetchAndAddOrdered(valueToAdd);
216 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
218 return fetchAndAddOrdered(valueToAdd);
221 // Test and set for pointers
223 template <typename T>
224 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
227 if (_q_value == expectedValue) {
236 template <typename T>
237 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
239 return testAndSetOrdered(expectedValue, newValue);
242 template <typename T>
243 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
245 return testAndSetOrdered(expectedValue, newValue);
248 template <typename T>
249 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
251 return testAndSetOrdered(expectedValue, newValue);
254 // Fetch and store for pointers
256 template <typename T>
257 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
260 T *returnValue = (_q_value);
266 template <typename T>
267 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
269 return fetchAndStoreOrdered(newValue);
272 template <typename T>
273 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
275 return fetchAndStoreOrdered(newValue);
278 template <typename T>
279 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
281 return fetchAndStoreOrdered(newValue);
284 // Fetch and add for pointers
286 template <typename T>
287 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
290 T *returnValue = (_q_value);
291 _q_value += valueToAdd;
296 template <typename T>
297 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
299 return fetchAndAddOrdered(valueToAdd);
302 template <typename T>
303 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
305 return fetchAndAddOrdered(valueToAdd);
308 template <typename T>
309 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
311 return fetchAndAddOrdered(valueToAdd);
316 #endif // generic implementation with taskLock()
320 #endif // QATOMIC_VXWORKS_H