qatomic_symbian.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_SYMBIAN_H
00043 #define QATOMIC_SYMBIAN_H
00044 
00045 #include <QtCore/qglobal.h>
00046 #include <e32std.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Core)
00053 
00054 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_SOMETIMES_NATIVE
00055 
00056 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
00057 { return false; }
00058 
00059 #define Q_ATOMIC_INT_TEST_AND_SET_IS_SOMETIMES_NATIVE
00060 
00061 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
00062 { return false; }
00063 
00064 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_SOMETIMES_NATIVE
00065 
00066 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
00067 { return false; }
00068 
00069 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_SOMETIMES_NATIVE
00070 
00071 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
00072 { return false; }
00073 
00074 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_SOMETIMES_NATIVE
00075 
00076 Q_CORE_EXPORT bool QBasicAtomicPointer_isTestAndSetNative();
00077 template <typename T>
00078 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
00079 { return QBasicAtomicPointer_isTestAndSetNative(); }
00080 template <typename T>
00081 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
00082 { return false; }
00083 
00084 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_SOMETIMES_NATIVE
00085 
00086 Q_CORE_EXPORT bool QBasicAtomicPointer_isFetchAndStoreNative();
00087 template <typename T>
00088 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
00089 { return QBasicAtomicPointer_isFetchAndStoreNative(); }
00090 template <typename T>
00091 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
00092 { return false; }
00093 
00094 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_SOMETIMES_NATIVE
00095 
00096 Q_CORE_EXPORT bool QBasicAtomicPointer_isFetchAndAddNative();
00097 template <typename T>
00098 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
00099 { return QBasicAtomicPointer_isFetchAndAddNative(); }
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 Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetRelaxed(volatile int *, int, int);
00108 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreRelaxed(volatile int *, int);
00109 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddRelaxed(volatile int *, int);
00110 Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetAcquire(volatile int *, int, int);
00111 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreAcquire(volatile int *, int);
00112 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddAcquire(volatile int *, int);
00113 Q_CORE_EXPORT bool QBasicAtomicInt_testAndSetRelease(volatile int *, int, int);
00114 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndStoreRelease(volatile int *, int);
00115 Q_CORE_EXPORT int QBasicAtomicInt_fetchAndAddRelease(volatile int *, int);
00116 
00117 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetOrdered(void * volatile *, void *, void *);
00118 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreOrdered(void * volatile *, void *);
00119 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddOrdered(void * volatile *, qptrdiff);
00120 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetRelaxed(void * volatile *, void *, void *);
00121 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreRelaxed(void * volatile *, void *);
00122 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddRelaxed(void * volatile *, qptrdiff);
00123 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetAcquire(void * volatile *, void *, void *);
00124 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreAcquire(void * volatile *, void *);
00125 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddAcquire(void * volatile *, qptrdiff);
00126 Q_CORE_EXPORT bool QBasicAtomicPointer_testAndSetRelease(void * volatile *, void *, void *);
00127 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndStoreRelease(void * volatile *, void *);
00128 Q_CORE_EXPORT void *QBasicAtomicPointer_fetchAndAddRelease(void * volatile *, qptrdiff);
00129 
00130 // Reference counting
00131 
00132 //LockedInc and LockedDec are machine coded for ARMv6 (and future proof)
00133 inline bool QBasicAtomicInt::ref()
00134 {
00135     int original = User::LockedInc((TInt&)_q_value);
00136     return original != -1;
00137 }
00138 
00139 inline bool QBasicAtomicInt::deref()
00140 {
00141     int original = User::LockedDec((TInt&)_q_value);
00142     return original != 1;
00143 }
00144 
00145 // Test and set for integers
00146 
00147 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
00148 {
00149     return QBasicAtomicInt_testAndSetOrdered(&_q_value, expectedValue, newValue);
00150 }
00151 
00152 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
00153 {
00154     return QBasicAtomicInt_testAndSetRelaxed(&_q_value, expectedValue, newValue);
00155 }
00156 
00157 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
00158 {
00159     return QBasicAtomicInt_testAndSetAcquire(&_q_value, expectedValue, newValue);
00160 }
00161 
00162 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
00163 {
00164     return QBasicAtomicInt_testAndSetRelease(&_q_value, expectedValue, newValue);
00165 }
00166 
00167 // Fetch and store for integers
00168 
00169 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
00170 {
00171     return QBasicAtomicInt_fetchAndStoreOrdered(&_q_value, newValue);
00172 }
00173 
00174 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
00175 {
00176     return QBasicAtomicInt_fetchAndStoreRelaxed(&_q_value, newValue);
00177 }
00178 
00179 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
00180 {
00181     return QBasicAtomicInt_fetchAndStoreAcquire(&_q_value, newValue);
00182 }
00183 
00184 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
00185 {
00186     return QBasicAtomicInt_fetchAndStoreRelease(&_q_value, newValue);
00187 }
00188 
00189 // Fetch and add for integers
00190 
00191 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
00192 {
00193     return QBasicAtomicInt_fetchAndAddOrdered(&_q_value, valueToAdd);
00194 }
00195 
00196 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
00197 {
00198     return QBasicAtomicInt_fetchAndAddRelaxed(&_q_value, valueToAdd);
00199 }
00200 
00201 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
00202 {
00203     return QBasicAtomicInt_fetchAndAddAcquire(&_q_value, valueToAdd);
00204 }
00205 
00206 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
00207 {
00208     return QBasicAtomicInt_fetchAndAddRelease(&_q_value, valueToAdd);
00209 }
00210 
00211 // Test and set for pointers
00212 
00213 template <typename T>
00214 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
00215 {
00216     return QBasicAtomicPointer_testAndSetOrdered(reinterpret_cast<void * volatile *>(&_q_value),
00217         expectedValue, newValue);
00218 }
00219 
00220 template <typename T>
00221 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
00222 {
00223     return QBasicAtomicPointer_testAndSetRelaxed(reinterpret_cast<void * volatile *>(&_q_value),
00224         expectedValue, newValue);
00225 }
00226 
00227 template <typename T>
00228 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
00229 {
00230     return QBasicAtomicPointer_testAndSetAcquire(reinterpret_cast<void * volatile *>(&_q_value),
00231         expectedValue, newValue);
00232 }
00233 
00234 template <typename T>
00235 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
00236 {
00237     return QBasicAtomicPointer_testAndSetRelease(reinterpret_cast<void * volatile *>(&_q_value),
00238         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     return static_cast<T*>(QBasicAtomicPointer_fetchAndStoreOrdered(
00247         reinterpret_cast<void * volatile *>(&_q_value)
00248         , newValue));
00249 }
00250 
00251 template <typename T>
00252 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
00253 {
00254     return static_cast<T*>(QBasicAtomicPointer_fetchAndStoreRelaxed(
00255         reinterpret_cast<void * volatile *>(&_q_value)
00256         , newValue));
00257 }
00258 
00259 template <typename T>
00260 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
00261 {
00262     return static_cast<T*>(QBasicAtomicPointer_fetchAndStoreAcquire(
00263         reinterpret_cast<void * volatile *>(&_q_value)
00264         , newValue));
00265 }
00266 
00267 template <typename T>
00268 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
00269 {
00270     return static_cast<T*>(QBasicAtomicPointer_fetchAndStoreRelease(
00271         reinterpret_cast<void * volatile *>(&_q_value)
00272         , newValue));
00273 }
00274 
00275 // Fetch and add for pointers
00276 
00277 template <typename T>
00278 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
00279 {
00280     return static_cast<T*>(QBasicAtomicPointer_fetchAndAddOrdered(
00281         reinterpret_cast<void * volatile *>(&_q_value),
00282         valueToAdd * sizeof(T)));
00283 }
00284 
00285 template <typename T>
00286 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
00287 {
00288     return static_cast<T*>(QBasicAtomicPointer_fetchAndAddRelaxed(
00289         reinterpret_cast<void * volatile *>(&_q_value),
00290         valueToAdd * sizeof(T)));
00291 }
00292 
00293 template <typename T>
00294 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
00295 {
00296     return static_cast<T*>(QBasicAtomicPointer_fetchAndAddAcquire(
00297         reinterpret_cast<void * volatile *>(&_q_value),
00298         valueToAdd * sizeof(T)));
00299 }
00300 
00301 template <typename T>
00302 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
00303 {
00304     return static_cast<T*>(QBasicAtomicPointer_fetchAndAddRelease(
00305         reinterpret_cast<void * volatile *>(&_q_value),
00306         valueToAdd * sizeof(T)));
00307 }
00308 
00309 QT_END_NAMESPACE
00310 
00311 QT_END_HEADER
00312 
00313 #endif // QATOMIC_SYMBIAN_H