Remove qatomic_arch.h
[profile/ivi/qtbase.git] / src / corelib / arch / qatomic_vxworks.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the qmake spec of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QATOMIC_VXWORKS_H
43 #define QATOMIC_VXWORKS_H
44
45 QT_BEGIN_HEADER
46
47 #if defined(__ppc)
48 #  include <QtCore/qatomic_powerpc.h>
49 #else // generic implementation with taskLock()
50
51 #include <QtCore/qoldbasicatomic.h>
52
53 #if 0
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>
57 #  include <taskLib.h>
58 #else
59 extern "C" int taskLock();
60 extern "C" int taskUnlock();
61 #endif
62
63
64
65 QT_BEGIN_NAMESPACE
66
67 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
68
69 inline bool QBasicAtomicInt::isReferenceCountingNative()
70 { return false; }
71 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
72 { return false; }
73
74 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
75
76 inline bool QBasicAtomicInt::isTestAndSetNative()
77 { return false; }
78 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
79 { return false; }
80
81 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
82
83 inline bool QBasicAtomicInt::isFetchAndStoreNative()
84 { return false; }
85 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
86 { return false; }
87
88 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
89
90 inline bool QBasicAtomicInt::isFetchAndAddNative()
91 { return false; }
92 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
93 { return false; }
94
95 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
96
97 template <typename T>
98 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
99 { return false; }
100 template <typename T>
101 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
102 { return false; }
103
104 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
105
106 template <typename T>
107 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
108 { return false; }
109 template <typename T>
110 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
111 { return false; }
112
113 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
114
115 template <typename T>
116 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
117 { return false; }
118 template <typename T>
119 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
120 { return false; }
121
122 // Reference counting
123
124 inline bool QBasicAtomicInt::ref()
125 {
126     taskLock();
127     bool ret = (++_q_value != 0);
128     taskUnlock();
129     return ret;
130 }
131
132 inline bool QBasicAtomicInt::deref()
133 {
134     taskLock();
135     bool ret = (--_q_value != 0);
136     taskUnlock();
137     return ret;
138 }
139
140 // Test-and-set for integers
141
142 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
143 {
144     taskLock();
145     if (_q_value == expectedValue) {
146         _q_value = newValue;
147         taskUnlock();
148         return true;
149     }
150     taskUnlock();
151     return false;
152 }
153
154 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
155 {
156     return testAndSetOrdered(expectedValue, newValue);
157 }
158
159 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
160 {
161     return testAndSetOrdered(expectedValue, newValue);
162 }
163
164 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
165 {
166     return testAndSetOrdered(expectedValue, newValue);
167 }
168
169 // Fetch-and-store for integers
170
171 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
172 {
173     taskLock();
174     int returnValue = _q_value;
175     _q_value = newValue;
176     taskUnlock();
177     return returnValue;
178 }
179
180 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
181 {
182     return fetchAndStoreOrdered(newValue);
183 }
184
185 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
186 {
187     return fetchAndStoreOrdered(newValue);
188 }
189
190 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
191 {
192     return fetchAndStoreOrdered(newValue);
193 }
194
195 // Fetch-and-add for integers
196
197 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
198 {
199     taskLock();
200     int originalValue = _q_value;
201     _q_value += valueToAdd;
202     taskUnlock();
203     return originalValue;
204 }
205
206 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
207 {
208     return fetchAndAddOrdered(valueToAdd);
209 }
210
211 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
212 {
213     return fetchAndAddOrdered(valueToAdd);
214 }
215
216 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
217 {
218     return fetchAndAddOrdered(valueToAdd);
219 }
220
221 // Test and set for pointers
222
223 template <typename T>
224 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
225 {
226     taskLock();
227     if (_q_value == expectedValue) {
228         _q_value = newValue;
229         taskUnlock();
230         return true;
231     }
232     taskUnlock();
233     return false;
234 }
235
236 template <typename T>
237 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
238 {
239     return testAndSetOrdered(expectedValue, newValue);
240 }
241
242 template <typename T>
243 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
244 {
245     return testAndSetOrdered(expectedValue, newValue);
246 }
247
248 template <typename T>
249 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
250 {
251     return testAndSetOrdered(expectedValue, newValue);
252 }
253
254 // Fetch and store for pointers
255
256 template <typename T>
257 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
258 {
259     taskLock();
260     T *returnValue = (_q_value);
261     _q_value = newValue;
262     taskUnlock();
263     return returnValue;
264 }
265
266 template <typename T>
267 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
268 {
269     return fetchAndStoreOrdered(newValue);
270 }
271
272 template <typename T>
273 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
274 {
275     return fetchAndStoreOrdered(newValue);
276 }
277
278 template <typename T>
279 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
280 {
281     return fetchAndStoreOrdered(newValue);
282 }
283
284 // Fetch and add for pointers
285
286 template <typename T>
287 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
288 {
289     taskLock();
290     T *returnValue = (_q_value);
291     _q_value += valueToAdd;
292     taskUnlock();
293     return returnValue;
294 }
295
296 template <typename T>
297 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
298 {
299     return fetchAndAddOrdered(valueToAdd);
300 }
301
302 template <typename T>
303 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
304 {
305     return fetchAndAddOrdered(valueToAdd);
306 }
307
308 template <typename T>
309 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
310 {
311     return fetchAndAddOrdered(valueToAdd);
312 }
313
314 QT_END_NAMESPACE
315
316 #endif // generic implementation with taskLock()
317
318 QT_END_HEADER
319
320 #endif // QATOMIC_VXWORKS_H