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

- File List
- File Members

# qatomic_generic.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_GENERIC_H
    00043 #define QATOMIC_GENERIC_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 Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetOrdered(volatile int *, int, int);
    00105 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreOrdered(volatile int *, int);
    00106 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddOrdered(volatile int *, int);
    00107
    00108 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetOrdered(void * volatile *, void *, void *);
    00109 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreOrdered(void * volatile *, void *);
    00110 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddOrdered(void * volatile *, qptrdiff);
    00111
    00112 // Reference counting
    00113
    00114 inline bool QBasicAtomicInt::ref()
    00115 {
    00116     return QBasicAtomicInt_fetchAndAddOrdered(&_q_value, 1) != -1;
    00117 }
    00118
    00119 inline bool QBasicAtomicInt::deref()
    00120 {
    00121     return QBasicAtomicInt_fetchAndAddOrdered(&_q_value, -1) != 1;
    00122 }
    00123
    00124 // Test and set for integers
    00125
    00126 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
    00127 {
    00128     return QBasicAtomicInt_testAndSetOrdered(&_q_value, expectedValue, newValue);
    00129 }
    00130
    00131 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
    00132 {
    00133     return testAndSetOrdered(expectedValue, newValue);
    00134 }
    00135
    00136 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
    00137 {
    00138     return testAndSetOrdered(expectedValue, newValue);
    00139 }
    00140
    00141 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
    00142 {
    00143     return testAndSetOrdered(expectedValue, newValue);
    00144 }
    00145
    00146 // Fetch and store for integers
    00147
    00148 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
    00149 {
    00150     return QBasicAtomicInt_fetchAndStoreOrdered(&_q_value, newValue);
    00151 }
    00152
    00153 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
    00154 {
    00155     return fetchAndStoreOrdered(newValue);
    00156 }
    00157
    00158 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
    00159 {
    00160     return fetchAndStoreOrdered(newValue);
    00161 }
    00162
    00163 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
    00164 {
    00165     return fetchAndStoreOrdered(newValue);
    00166 }
    00167
    00168 // Fetch and add for integers
    00169
    00170 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
    00171 {
    00172     return QBasicAtomicInt_fetchAndAddOrdered(&_q_value, valueToAdd);
    00173 }
    00174
    00175 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
    00176 {
    00177     return fetchAndAddOrdered(valueToAdd);
    00178 }
    00179
    00180 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
    00181 {
    00182     return fetchAndAddOrdered(valueToAdd);
    00183 }
    00184
    00185 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
    00186 {
    00187     return fetchAndAddOrdered(valueToAdd);
    00188 }
    00189
    00190 // Test and set for pointers
    00191
    00192 template <typename T>
    00193 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
    00194 {
    00195     union { T * volatile * typed; void * volatile * voidp; } pointer;
    00196     pointer.typed = &_q_value;
    00197     return QBasicAtomicPointer_testAndSetOrdered(pointer.voidp, expectedValue, newValue);
    00198 }
    00199
    00200 template <typename T>
    00201 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
    00202 {
    00203     return testAndSetOrdered(expectedValue, newValue);
    00204 }
    00205
    00206 template <typename T>
    00207 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
    00208 {
    00209     return testAndSetOrdered(expectedValue, newValue);
    00210 }
    00211
    00212 template <typename T>
    00213 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
    00214 {
    00215     return testAndSetOrdered(expectedValue, newValue);
    00216 }
    00217
    00218 // Fetch and store for pointers
    00219
    00220 template <typename T>
    00221 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
    00222 {
    00223     union { T * volatile * typed; void * volatile * voidp; } pointer;
    00224     union { T *typed; void *voidp; } returnValue;
    00225     pointer.typed = &_q_value;
    00226     returnValue.voidp = QBasicAtomicPointer_fetchAndStoreOrdered(pointer.voidp, newValue);
    00227     return returnValue.typed;
    00228 }
    00229
    00230 template <typename T>
    00231 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
    00232 {
    00233     return fetchAndStoreOrdered(newValue);
    00234 }
    00235
    00236 template <typename T>
    00237 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
    00238 {
    00239     return fetchAndStoreOrdered(newValue);
    00240 }
    00241
    00242 template <typename T>
    00243 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
    00244 {
    00245     return fetchAndStoreOrdered(newValue);
    00246 }
    00247
    00248 // Fetch and add for pointers
    00249
    00250 template <typename T>
    00251 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
    00252 {
    00253     union { T * volatile *typed; void * volatile *voidp; } pointer;
    00254     union { T *typed; void *voidp; } returnValue;
    00255     pointer.typed = &_q_value;
    00256     returnValue.voidp = QBasicAtomicPointer_fetchAndAddOrdered(pointer.voidp, valueToAdd * sizeof(T));
    00257     return returnValue.typed;
    00258 }
    00259
    00260 template <typename T>
    00261 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
    00262 {
    00263     return fetchAndAddOrdered(valueToAdd);
    00264 }
    00265
    00266 template <typename T>
    00267 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
    00268 {
    00269     return fetchAndAddOrdered(valueToAdd);
    00270 }
    00271
    00272 template <typename T>
    00273 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
    00274 {
    00275     return fetchAndAddOrdered(valueToAdd);
    00276 }
    00277
    00278 QT_END_NAMESPACE
    00279
    00280 QT_END_HEADER
    00281
    00282 #endif // QATOMIC_GENERIC_H