QtCore/qatomic_parisc.h Source File

qatomic_parisc.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_PARISC_H
43 #define QATOMIC_PARISC_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 extern "C" {
105  Q_CORE_EXPORT void q_atomic_lock(int *lock);
106  Q_CORE_EXPORT void q_atomic_unlock(int *lock);
107 }
108 
109 // Reference counting
110 
111 inline bool QBasicAtomicInt::ref()
112 {
113  q_atomic_lock(_q_lock);
114  bool ret = (++_q_value != 0);
115  q_atomic_unlock(_q_lock);
116  return ret;
117 }
118 
119 inline bool QBasicAtomicInt::deref()
120 {
121  q_atomic_lock(_q_lock);
122  bool ret = (--_q_value != 0);
123  q_atomic_unlock(_q_lock);
124  return ret;
125 }
126 
127 // Test-and-set for integers
128 
129 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
130 {
131  q_atomic_lock(_q_lock);
132  if (_q_value == expectedValue) {
133  _q_value = newValue;
134  q_atomic_unlock(_q_lock);
135  return true;
136  }
137  q_atomic_unlock(_q_lock);
138  return false;
139 }
140 
141 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
142 {
143  return testAndSetOrdered(expectedValue, newValue);
144 }
145 
146 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
147 {
148  return testAndSetOrdered(expectedValue, newValue);
149 }
150 
151 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
152 {
153  return testAndSetOrdered(expectedValue, newValue);
154 }
155 
156 // Fetch-and-store for integers
157 
158 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
159 {
160  q_atomic_lock(_q_lock);
161  int returnValue = _q_value;
162  _q_value = newValue;
163  q_atomic_unlock(_q_lock);
164  return returnValue;
165 }
166 
167 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
168 {
169  return fetchAndStoreOrdered(newValue);
170 }
171 
172 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
173 {
174  return fetchAndStoreOrdered(newValue);
175 }
176 
177 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
178 {
179  return fetchAndStoreOrdered(newValue);
180 }
181 
182 // Fetch-and-add for integers
183 
184 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
185 {
186  q_atomic_lock(_q_lock);
187  int originalValue = _q_value;
188  _q_value += valueToAdd;
189  q_atomic_unlock(_q_lock);
190  return originalValue;
191 }
192 
193 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
194 {
195  return fetchAndAddOrdered(valueToAdd);
196 }
197 
198 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
199 {
200  return fetchAndAddOrdered(valueToAdd);
201 }
202 
203 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
204 {
205  return fetchAndAddOrdered(valueToAdd);
206 }
207 
208 // Test and set for pointers
209 
210 template <typename T>
211 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
212 {
213  q_atomic_lock(_q_lock);
214  if (_q_value == expectedValue) {
215  _q_value = newValue;
216  q_atomic_unlock(_q_lock);
217  return true;
218  }
219  q_atomic_unlock(_q_lock);
220  return false;
221 }
222 
223 template <typename T>
224 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
225 {
226  return testAndSetOrdered(expectedValue, newValue);
227 }
228 
229 template <typename T>
230 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
231 {
232  return testAndSetOrdered(expectedValue, newValue);
233 }
234 
235 template <typename T>
236 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
237 {
238  return testAndSetOrdered(expectedValue, newValue);
239 }
240 
241 // Fetch and store for pointers
242 
243 template <typename T>
244 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
245 {
246  q_atomic_lock(_q_lock);
247  T *returnValue = (_q_value);
248  _q_value = newValue;
249  q_atomic_unlock(_q_lock);
250  return returnValue;
251 }
252 
253 template <typename T>
254 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
255 {
256  return fetchAndStoreOrdered(newValue);
257 }
258 
259 template <typename T>
260 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
261 {
262  return fetchAndStoreOrdered(newValue);
263 }
264 
265 template <typename T>
266 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
267 {
268  return fetchAndStoreOrdered(newValue);
269 }
270 
271 // Fetch and add for pointers
272 
273 template <typename T>
274 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
275 {
276  q_atomic_lock(_q_lock);
277  T *returnValue = (_q_value);
278  _q_value += valueToAdd;
279  q_atomic_unlock(_q_lock);
280  return returnValue;
281 }
282 
283 template <typename T>
284 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
285 {
286  return fetchAndAddOrdered(valueToAdd);
287 }
288 
289 template <typename T>
290 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
291 {
292  return fetchAndAddOrdered(valueToAdd);
293 }
294 
295 template <typename T>
296 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
297 {
298  return fetchAndAddOrdered(valueToAdd);
299 }
300 
302 
304 
305 #endif // QATOMIC_PARISC_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
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
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
bool testAndSetAcquire(T *expectedValue, T *newValue)
static bool isFetchAndAddWaitFree()
Definition: qatomic_alpha.h:74
T * fetchAndStoreOrdered(T *newValue)
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
int fetchAndAddOrdered(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
Q_CORE_EXPORT void q_atomic_unlock(int *lock)
int fetchAndAddRelease(int valueToAdd)
Q_CORE_EXPORT void q_atomic_lock(int *lock)
int fetchAndStoreRelease(int newValue)