- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qatomic_parisc.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QATOMIC_PARISC_H
    00043 #define QATOMIC_PARISC_H
    00044
    00045 QT_BEGIN_HEADER
    00046
    00047 QT_BEGIN_NAMESPACE
    00048
    00049 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
    00050
    00051 inline bool QBasicAtomicInt::isReferenceCountingNative()
    00052 { return false; }
    00053 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
    00054 { return false; }
    00055
    00056 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
    00057
    00058 inline bool QBasicAtomicInt::isTestAndSetNative()
    00059 { return false; }
    00060 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
    00061 { return false; }
    00062
    00063 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
    00064
    00065 inline bool QBasicAtomicInt::isFetchAndStoreNative()
    00066 { return false; }
    00067 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
    00068 { return false; }
    00069
    00070 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
    00071
    00072 inline bool QBasicAtomicInt::isFetchAndAddNative()
    00073 { return false; }
    00074 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
    00075 { return false; }
    00076
    00077 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
    00078
    00079 template <typename T>
    00080 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
    00081 { return false; }
    00082 template <typename T>
    00083 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
    00084 { return false; }
    00085
    00086 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
    00087
    00088 template <typename T>
    00089 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
    00090 { return false; }
    00091 template <typename T>
    00092 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
    00093 { return false; }
    00094
    00095 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
    00096
    00097 template <typename T>
    00098 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
    00099 { return false; }
    00100 template <typename T>
    00101 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
    00102 { return false; }
    00103
    00104 extern "C" {
    00105     Q_CORE_EXPORT void q_atomic_lock(int *lock);
    00106     Q_CORE_EXPORT void q_atomic_unlock(int *lock);
    00107 }
    00108
    00109 // Reference counting
    00110
    00111 inline bool QBasicAtomicInt::ref()
    00112 {
    00113     q_atomic_lock(_q_lock);
    00114     bool ret = (++_q_value != 0);
    00115     q_atomic_unlock(_q_lock);
    00116     return ret;
    00117 }
    00118
    00119 inline bool QBasicAtomicInt::deref()
    00120 {
    00121     q_atomic_lock(_q_lock);
    00122     bool ret = (--_q_value != 0);
    00123     q_atomic_unlock(_q_lock);
    00124     return ret;
    00125 }
    00126
    00127 // Test-and-set for integers
    00128
    00129 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
    00130 {
    00131     q_atomic_lock(_q_lock);
    00132     if (_q_value == expectedValue) {
    00133         _q_value = newValue;
    00134         q_atomic_unlock(_q_lock);
    00135         return true;
    00136     }
    00137     q_atomic_unlock(_q_lock);
    00138     return false;
    00139 }
    00140
    00141 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
    00142 {
    00143     return testAndSetOrdered(expectedValue, newValue);
    00144 }
    00145
    00146 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
    00147 {
    00148     return testAndSetOrdered(expectedValue, newValue);
    00149 }
    00150
    00151 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
    00152 {
    00153     return testAndSetOrdered(expectedValue, newValue);
    00154 }
    00155
    00156 // Fetch-and-store for integers
    00157
    00158 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
    00159 {
    00160     q_atomic_lock(_q_lock);
    00161     int returnValue = _q_value;
    00162     _q_value = newValue;
    00163     q_atomic_unlock(_q_lock);
    00164     return returnValue;
    00165 }
    00166
    00167 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
    00168 {
    00169     return fetchAndStoreOrdered(newValue);
    00170 }
    00171
    00172 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
    00173 {
    00174     return fetchAndStoreOrdered(newValue);
    00175 }
    00176
    00177 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
    00178 {
    00179     return fetchAndStoreOrdered(newValue);
    00180 }
    00181
    00182 // Fetch-and-add for integers
    00183
    00184 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
    00185 {
    00186     q_atomic_lock(_q_lock);
    00187     int originalValue = _q_value;
    00188     _q_value += valueToAdd;
    00189     q_atomic_unlock(_q_lock);
    00190     return originalValue;
    00191 }
    00192
    00193 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
    00194 {
    00195     return fetchAndAddOrdered(valueToAdd);
    00196 }
    00197
    00198 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
    00199 {
    00200     return fetchAndAddOrdered(valueToAdd);
    00201 }
    00202
    00203 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
    00204 {
    00205     return fetchAndAddOrdered(valueToAdd);
    00206 }
    00207
    00208 // Test and set for pointers
    00209
    00210 template <typename T>
    00211 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
    00212 {
    00213     q_atomic_lock(_q_lock);
    00214     if (_q_value == expectedValue) {
    00215         _q_value = newValue;
    00216         q_atomic_unlock(_q_lock);
    00217         return true;
    00218     }
    00219     q_atomic_unlock(_q_lock);
    00220     return false;
    00221 }
    00222
    00223 template <typename T>
    00224 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
    00225 {
    00226     return testAndSetOrdered(expectedValue, newValue);
    00227 }
    00228
    00229 template <typename T>
    00230 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
    00231 {
    00232     return testAndSetOrdered(expectedValue, newValue);
    00233 }
    00234
    00235 template <typename T>
    00236 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
    00237 {
    00238     return testAndSetOrdered(expectedValue, newValue);
    00239 }
    00240
    00241 // Fetch and store for pointers
    00242
    00243 template <typename T>
    00244 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
    00245 {
    00246     q_atomic_lock(_q_lock);
    00247     T *returnValue = (_q_value);
    00248     _q_value = newValue;
    00249     q_atomic_unlock(_q_lock);
    00250     return returnValue;
    00251 }
    00252
    00253 template <typename T>
    00254 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
    00255 {
    00256     return fetchAndStoreOrdered(newValue);
    00257 }
    00258
    00259 template <typename T>
    00260 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
    00261 {
    00262     return fetchAndStoreOrdered(newValue);
    00263 }
    00264
    00265 template <typename T>
    00266 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
    00267 {
    00268     return fetchAndStoreOrdered(newValue);
    00269 }
    00270
    00271 // Fetch and add for pointers
    00272
    00273 template <typename T>
    00274 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
    00275 {
    00276     q_atomic_lock(_q_lock);
    00277     T *returnValue = (_q_value);
    00278     _q_value += valueToAdd;
    00279     q_atomic_unlock(_q_lock);
    00280     return returnValue;
    00281 }
    00282
    00283 template <typename T>
    00284 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
    00285 {
    00286     return fetchAndAddOrdered(valueToAdd);
    00287 }
    00288
    00289 template <typename T>
    00290 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
    00291 {
    00292     return fetchAndAddOrdered(valueToAdd);
    00293 }
    00294
    00295 template <typename T>
    00296 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
    00297 {
    00298     return fetchAndAddOrdered(valueToAdd);
    00299 }
    00300
    00301 QT_END_NAMESPACE
    00302
    00303 QT_END_HEADER
    00304
    00305 #endif // QATOMIC_PARISC_H