Qt 4.8
qatomic_sparc.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_SPARC_H
43 #define QATOMIC_SPARC_H
44 
46 
48 
49 #if defined(_LP64)
50 
51 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
52 
54 { return true; }
56 { return false; }
57 
58 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
59 #define Q_ATOMIC_INT_TEST_AND_SET_IS_WAIT_FREE
60 
62 { return true; }
64 { return true; }
65 
66 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
67 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_WAIT_FREE
68 
70 { return true; }
72 { return true; }
73 
74 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
75 
77 { return true; }
79 { return false; }
80 
81 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
82 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_WAIT_FREE
83 
84 template <typename T>
86 { return true; }
87 template <typename T>
89 { return true; }
90 
91 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
92 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_WAIT_FREE
93 
94 template <typename T>
96 { return true; }
97 template <typename T>
99 { return true; }
100 
101 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
102 
103 template <typename T>
105 { return true; }
106 template <typename T>
108 { return false; }
109 
110 extern "C" {
111  Q_CORE_EXPORT int q_atomic_increment(volatile int *ptr);
112  Q_CORE_EXPORT int q_atomic_decrement(volatile int *ptr);
113 
114  Q_CORE_EXPORT int q_atomic_test_and_set_int(volatile int *ptr, int expected, int newval);
116  int expected,
117  int newval);
119  int expected,
120  int newval);
121 
122  Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval);
123  Q_CORE_EXPORT int q_atomic_fetch_and_store_acquire_int(volatile int *ptr, int newval);
124  Q_CORE_EXPORT int q_atomic_fetch_and_store_release_int(volatile int *ptr, int newval);
125 
126  Q_CORE_EXPORT int q_atomic_fetch_and_add_int(volatile int *ptr, int value);
127  Q_CORE_EXPORT int q_atomic_fetch_and_add_acquire_int(volatile int *ptr, int value);
128  Q_CORE_EXPORT int q_atomic_fetch_and_add_release_int(volatile int *ptr, int value);
129 
130  Q_CORE_EXPORT int q_atomic_test_and_set_ptr(volatile void *ptr, const void *expected, const void *newval);
132  const void *expected,
133  const void *newval);
135  const void *expected,
136  const void *newval);
137 
138  Q_CORE_EXPORT void *q_atomic_set_ptr(volatile void *ptr, const void *newval);
139  Q_CORE_EXPORT void *q_atomic_fetch_and_store_acquire_ptr(volatile void *ptr, const void *newval);
140  Q_CORE_EXPORT void *q_atomic_fetch_and_store_release_ptr(volatile void *ptr, const void *newval);
141 
142  Q_CORE_EXPORT void *q_atomic_fetch_and_add_ptr(volatile void *ptr, int value);
143  Q_CORE_EXPORT void *q_atomic_fetch_and_add_acquire_ptr(volatile void *ptr, int value);
144  Q_CORE_EXPORT void *q_atomic_fetch_and_add_release_ptr(volatile void *ptr, int value);
145 }
146 
147 inline bool QBasicAtomicInt::ref()
148 {
149  return fetchAndAddRelaxed(1) != -1;
150 }
151 
152 inline bool QBasicAtomicInt::deref()
153 {
154  return fetchAndAddRelaxed(-1) != 1;
155 }
156 
157 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
158 {
159  return q_atomic_test_and_set_int(&_q_value, expectedValue, newValue) != 0;
160 }
161 
162 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
163 {
164  return q_atomic_test_and_set_acquire_int(&_q_value, expectedValue, newValue) != 0;
165 }
166 
167 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
168 {
169  return q_atomic_test_and_set_release_int(&_q_value, expectedValue, newValue) != 0;
170 }
171 
172 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
173 {
174  return q_atomic_test_and_set_acquire_int(&_q_value, expectedValue, newValue) != 0;
175 }
176 
177 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
178 {
179  return q_atomic_set_int(&_q_value, newValue);
180 }
181 
182 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
183 {
185 }
186 
187 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
188 {
190 }
191 
192 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
193 {
195 }
196 
197 inline int QBasicAtomicInt::fetchAndAddRelaxed(int newValue)
198 {
199  return q_atomic_fetch_and_add_int(&_q_value, newValue);
200 }
201 
202 inline int QBasicAtomicInt::fetchAndAddAcquire(int newValue)
203 {
204  return q_atomic_fetch_and_add_acquire_int(&_q_value, newValue);
205 }
206 
207 inline int QBasicAtomicInt::fetchAndAddRelease(int newValue)
208 {
209  return q_atomic_fetch_and_add_release_int(&_q_value, newValue);
210 }
211 
212 inline int QBasicAtomicInt::fetchAndAddOrdered(int newValue)
213 {
214  return q_atomic_fetch_and_add_acquire_int(&_q_value, newValue);
215 }
216 
217 template <typename T>
218 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
219 {
220  return q_atomic_test_and_set_ptr(&_q_value, expectedValue, newValue) != 0;
221 }
222 
223 template <typename T>
224 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
225 {
226  return q_atomic_test_and_set_acquire_ptr(&_q_value, expectedValue, newValue) != 0;
227 }
228 
229 template <typename T>
230 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
231 {
232  return q_atomic_test_and_set_release_ptr(&_q_value, expectedValue, newValue) != 0;
233 }
234 
235 template <typename T>
236 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
237 {
238  return q_atomic_test_and_set_acquire_ptr(&_q_value, expectedValue, newValue) != 0;
239 }
240 
241 template <typename T>
243 {
244  return reinterpret_cast<T *>(q_atomic_set_ptr(&_q_value, newValue));
245 }
246 
247 template <typename T>
249 {
250  return reinterpret_cast<T *>(q_atomic_fetch_and_store_acquire_ptr(&_q_value, newValue));
251 }
252 
253 template <typename T>
255 {
256  return reinterpret_cast<T *>(q_atomic_fetch_and_store_release_ptr(&_q_value, newValue));
257 }
258 
259 template <typename T>
261 {
262  return reinterpret_cast<T *>(q_atomic_fetch_and_store_acquire_ptr(&_q_value, newValue));
263 }
264 
265 template <typename T>
267 {
268  return reinterpret_cast<T *>(q_atomic_fetch_and_add_ptr(&_q_value, valueToAdd * sizeof(T)));
269 }
270 
271 template <typename T>
274 {
275  return reinterpret_cast<T *>(q_atomic_fetch_and_add_acquire_ptr(&_q_value, valueToAdd * sizeof(T)));
276 }
277 
278 template <typename T>
280 {
281  return reinterpret_cast<T *>(q_atomic_fetch_and_add_release_ptr(&_q_value, valueToAdd * sizeof(T)));
282 }
283 
284 template <typename T>
286 {
287  return reinterpret_cast<T *>(q_atomic_fetch_and_add_acquire_ptr(&_q_value, valueToAdd * sizeof(T)));
288 }
289 
290 #else
291 
292 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
293 
295 { return false; }
297 { return false; }
298 
299 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
300 
302 { return false; }
304 { return false; }
305 
306 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
307 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_WAIT_FREE
308 
310 { return true; }
312 { return true; }
313 
314 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
315 
317 { return false; }
319 { return false; }
320 
321 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
322 
323 template <typename T>
325 { return false; }
326 template <typename T>
328 { return false; }
329 
330 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
331 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_WAIT_FREE
332 
333 template <typename T>
335 { return true; }
336 template <typename T>
338 { return true; }
339 
340 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
341 
342 template <typename T>
344 { return false; }
345 template <typename T>
347 { return false; }
348 
349 extern "C" {
350  Q_CORE_EXPORT int q_atomic_lock_int(volatile int *addr);
351  Q_CORE_EXPORT int q_atomic_lock_ptr(volatile void *addr);
352  Q_CORE_EXPORT void q_atomic_unlock(volatile void *addr, int value);
353  Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval);
354  Q_CORE_EXPORT void *q_atomic_set_ptr(volatile void *ptr, void *newval);
355 } // extern "C"
356 
357 inline bool QBasicAtomicInt::ref()
358 {
359  const int val = q_atomic_lock_int(&_q_value);
360  q_atomic_unlock(&_q_value, val + 1);
361  return val != -1;
362 }
363 
364 inline bool QBasicAtomicInt::deref()
365 {
366  const int val = q_atomic_lock_int(&_q_value);
367  q_atomic_unlock(&_q_value, val - 1);
368  return val != 1;
369 }
370 
371 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
372 {
373  int val = q_atomic_lock_int(&_q_value);
374  if (val == expectedValue) {
375  q_atomic_unlock(&_q_value, newValue);
376  return true;
377  }
378  q_atomic_unlock(&_q_value, val);
379  return false;
380 }
381 
382 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
383 {
384  return testAndSetOrdered(expectedValue, newValue);
385 }
386 
387 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
388 {
389  return testAndSetOrdered(expectedValue, newValue);
390 }
391 
392 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
393 {
394  return testAndSetOrdered(expectedValue, newValue);
395 }
396 
397 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
398 {
399  return q_atomic_set_int(&_q_value, newValue);
400 }
401 
402 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
403 {
404  return fetchAndStoreOrdered(newValue);
405 }
406 
407 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
408 {
409  return fetchAndStoreOrdered(newValue);
410 }
411 
412 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
413 {
414  return fetchAndStoreOrdered(newValue);
415 }
416 
417 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
418 {
419  const int originalValue = q_atomic_lock_int(&_q_value);
420  q_atomic_unlock(&_q_value, originalValue + valueToAdd);
421  return originalValue;
422 }
423 
424 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
425 {
426  return fetchAndAddOrdered(valueToAdd);
427 }
428 
429 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
430 {
431  return fetchAndAddOrdered(valueToAdd);
432 }
433 
434 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
435 {
436  return fetchAndAddOrdered(valueToAdd);
437 }
438 
439 template <typename T>
440 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
441 {
442  T *val = reinterpret_cast<T *>(q_atomic_lock_ptr(&_q_value));
443  if (val == expectedValue) {
444  q_atomic_unlock(&_q_value, reinterpret_cast<int>(newValue));
445  return true;
446  }
447  q_atomic_unlock(&_q_value, reinterpret_cast<int>(val));
448  return false;
449 }
450 
451 template <typename T>
452 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
453 {
454  return testAndSetOrdered(expectedValue, newValue);
455 }
456 
457 template <typename T>
458 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
459 {
460  return testAndSetOrdered(expectedValue, newValue);
461 }
462 
463 template <typename T>
464 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
465 {
466  return testAndSetOrdered(expectedValue, newValue);
467 }
468 
469 template <typename T>
471 {
472  return reinterpret_cast<T *>(q_atomic_set_ptr(&_q_value, newValue));
473 }
474 
475 template <typename T>
477 {
478  return fetchAndStoreOrdered(newValue);
479 }
480 
481 template <typename T>
483 {
484  return fetchAndStoreOrdered(newValue);
485 }
486 
487 template <typename T>
489 {
490  return fetchAndStoreOrdered(newValue);
491 }
492 
493 template <typename T>
495 {
496  T *originalValue = reinterpret_cast<T *>(q_atomic_lock_ptr(&_q_value));
497  q_atomic_unlock(&_q_value, int(originalValue + valueToAdd));
498  return originalValue;
499 }
500 
501 template <typename T>
503 {
504  return fetchAndAddOrdered(valueToAdd);
505 }
506 
507 template <typename T>
509 {
510  return fetchAndAddOrdered(valueToAdd);
511 }
512 
513 template <typename T>
515 {
516  return fetchAndAddOrdered(valueToAdd);
517 }
518 
519 #endif // _LP64
520 
522 
524 
525 #endif // QATOMIC_SPARC_H
void * q_atomic_fetch_and_add_acquire_ptr(volatile void *ptr, qptrdiff valueToAdd)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:65
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:58
int fetchAndStoreRelease(int newValue)
int q_atomic_fetch_and_store_release_ptr(volatile void *ptr, void *newValue)
static bool isReferenceCountingNative()
Definition: qatomic_alpha.h:51
T * fetchAndAddRelaxed(qptrdiff valueToAdd)
Q_CORE_EXPORT int q_atomic_fetch_and_add_int(volatile int *ptr, int value)
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
Q_CORE_EXPORT int q_atomic_test_and_set_acquire_ptr(volatile void *ptr, void *expected, void *newval)
T * fetchAndStoreRelease(T *newValue)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
int q_atomic_fetch_and_store_release_int(volatile int *ptr, int newValue)
Q_CORE_EXPORT void * q_atomic_fetch_and_add_ptr(volatile void *ptr, int value)
int q_atomic_fetch_and_store_acquire_ptr(volatile void *ptr, void *newValue)
T * fetchAndAddRelease(qptrdiff valueToAdd)
Q_CORE_EXPORT void q_atomic_unlock(volatile void *addr, int value)
bool testAndSetOrdered(T *expectedValue, T *newValue)
int fetchAndAddAcquire(int valueToAdd)
Q_CORE_EXPORT int q_atomic_test_and_set_acquire_int(volatile int *ptr, int expected, int newval)
T * fetchAndAddAcquire(qptrdiff valueToAdd)
int fetchAndStoreRelaxed(int newValue)
T * fetchAndAddOrdered(qptrdiff valueToAdd)
bool testAndSetAcquire(int expectedValue, int newValue)
Q_CORE_EXPORT void * q_atomic_set_ptr(volatile void *ptr, void *newval)
bool testAndSetRelaxed(int expectedValue, int newValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_CORE_EXPORT int q_atomic_fetch_and_add_acquire_int(volatile int *ptr, int value)
Q_CORE_EXPORT int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected, void *newval)
int fetchAndStoreAcquire(int newValue)
Q_CORE_EXPORT int q_atomic_increment(volatile int *ptr)
QIntegerForSizeof< void * >::Signed qptrdiff
Definition: qglobal.h:987
Q_CORE_EXPORT int q_atomic_test_and_set_release_int(volatile int *ptr, int expected, int newval)
T * fetchAndStoreOrdered(T *newValue)
#define Q_INLINE_TEMPLATE
Definition: qglobal.h:1713
Q_CORE_EXPORT int q_atomic_lock_ptr(volatile void *addr)
int fetchAndAddRelease(int valueToAdd)
Q_CORE_EXPORT int q_atomic_fetch_and_add_release_int(volatile int *ptr, int value)
const T * ptr(const T &t)
bool testAndSetOrdered(int expectedValue, int newValue)
T * fetchAndStoreAcquire(T *newValue)
void * q_atomic_fetch_and_add_release_ptr(volatile void *ptr, qptrdiff valueToAdd)
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)
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
Q_CORE_EXPORT int q_atomic_test_and_set_int(volatile int *ptr, int expected, int newval)
Q_CORE_EXPORT int q_atomic_decrement(volatile int *ptr)
int fetchAndAddRelaxed(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
bool testAndSetRelaxed(T *expectedValue, T *newValue)
Q_CORE_EXPORT int q_atomic_set_int(volatile int *ptr, int newval)
Q_CORE_EXPORT int q_atomic_test_and_set_release_ptr(volatile void *ptr, void *expected, void *newval)
bool testAndSetRelease(T *expectedValue, T *newValue)
#define QT_END_HEADER
Definition: qglobal.h:137
int q_atomic_fetch_and_store_acquire_int(volatile int *ptr, int newValue)
Q_CORE_EXPORT int q_atomic_lock_int(volatile int *addr)
T * fetchAndStoreRelaxed(T *newValue)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:89
bool testAndSetAcquire(T *expectedValue, T *newValue)