qatomic_vxworks.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 qmake spec 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_VXWORKS_H
00043 #define QATOMIC_VXWORKS_H
00044 
00045 QT_BEGIN_HEADER
00046 
00047 #if defined(__ppc)
00048 #  include <QtCore/qatomic_powerpc.h>
00049 #else // generic implementation with taskLock()
00050 
00051 #if 0
00052 // we don't want to include the system header here for two function prototypes,
00053 // because it pulls in a _lot_ of stuff that pollutes the global namespace
00054 #  include <vxWorksCommon.h>
00055 #  include <taskLib.h>
00056 #else
00057 extern "C" int taskLock();
00058 extern "C" int taskUnlock();
00059 #endif
00060 
00061 
00062 
00063 QT_BEGIN_NAMESPACE
00064 
00065 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
00066 
00067 inline bool QBasicAtomicInt::isReferenceCountingNative()
00068 { return false; }
00069 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
00070 { return false; }
00071 
00072 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
00073 
00074 inline bool QBasicAtomicInt::isTestAndSetNative()
00075 { return false; }
00076 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
00077 { return false; }
00078 
00079 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
00080 
00081 inline bool QBasicAtomicInt::isFetchAndStoreNative()
00082 { return false; }
00083 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
00084 { return false; }
00085 
00086 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
00087 
00088 inline bool QBasicAtomicInt::isFetchAndAddNative()
00089 { return false; }
00090 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
00091 { return false; }
00092 
00093 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
00094 
00095 template <typename T>
00096 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
00097 { return false; }
00098 template <typename T>
00099 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
00100 { return false; }
00101 
00102 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
00103 
00104 template <typename T>
00105 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
00106 { return false; }
00107 template <typename T>
00108 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
00109 { return false; }
00110 
00111 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
00112 
00113 template <typename T>
00114 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
00115 { return false; }
00116 template <typename T>
00117 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
00118 { return false; }
00119 
00120 // Reference counting
00121 
00122 inline bool QBasicAtomicInt::ref()
00123 {
00124     taskLock();
00125     bool ret = (++_q_value != 0);
00126     taskUnlock();
00127     return ret;
00128 }
00129 
00130 inline bool QBasicAtomicInt::deref()
00131 {
00132     taskLock();
00133     bool ret = (--_q_value != 0);
00134     taskUnlock();
00135     return ret;
00136 }
00137 
00138 // Test-and-set for integers
00139 
00140 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
00141 {
00142     taskLock();
00143     if (_q_value == expectedValue) {
00144         _q_value = newValue;
00145         taskUnlock();
00146         return true;
00147     }
00148     taskUnlock();
00149     return false;
00150 }
00151 
00152 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
00153 {
00154     return testAndSetOrdered(expectedValue, newValue);
00155 }
00156 
00157 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
00158 {
00159     return testAndSetOrdered(expectedValue, newValue);
00160 }
00161 
00162 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
00163 {
00164     return testAndSetOrdered(expectedValue, newValue);
00165 }
00166 
00167 // Fetch-and-store for integers
00168 
00169 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
00170 {
00171     taskLock();
00172     int returnValue = _q_value;
00173     _q_value = newValue;
00174     taskUnlock();
00175     return returnValue;
00176 }
00177 
00178 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
00179 {
00180     return fetchAndStoreOrdered(newValue);
00181 }
00182 
00183 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
00184 {
00185     return fetchAndStoreOrdered(newValue);
00186 }
00187 
00188 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
00189 {
00190     return fetchAndStoreOrdered(newValue);
00191 }
00192 
00193 // Fetch-and-add for integers
00194 
00195 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
00196 {
00197     taskLock();
00198     int originalValue = _q_value;
00199     _q_value += valueToAdd;
00200     taskUnlock();
00201     return originalValue;
00202 }
00203 
00204 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
00205 {
00206     return fetchAndAddOrdered(valueToAdd);
00207 }
00208 
00209 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
00210 {
00211     return fetchAndAddOrdered(valueToAdd);
00212 }
00213 
00214 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
00215 {
00216     return fetchAndAddOrdered(valueToAdd);
00217 }
00218 
00219 // Test and set for pointers
00220 
00221 template <typename T>
00222 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
00223 {
00224     taskLock();
00225     if (_q_value == expectedValue) {
00226         _q_value = newValue;
00227         taskUnlock();
00228         return true;
00229     }
00230     taskUnlock();
00231     return false;
00232 }
00233 
00234 template <typename T>
00235 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
00236 {
00237     return testAndSetOrdered(expectedValue, newValue);
00238 }
00239 
00240 template <typename T>
00241 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
00242 {
00243     return testAndSetOrdered(expectedValue, newValue);
00244 }
00245 
00246 template <typename T>
00247 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
00248 {
00249     return testAndSetOrdered(expectedValue, newValue);
00250 }
00251 
00252 // Fetch and store for pointers
00253 
00254 template <typename T>
00255 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
00256 {
00257     taskLock();
00258     T *returnValue = (_q_value);
00259     _q_value = newValue;
00260     taskUnlock();
00261     return returnValue;
00262 }
00263 
00264 template <typename T>
00265 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
00266 {
00267     return fetchAndStoreOrdered(newValue);
00268 }
00269 
00270 template <typename T>
00271 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
00272 {
00273     return fetchAndStoreOrdered(newValue);
00274 }
00275 
00276 template <typename T>
00277 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
00278 {
00279     return fetchAndStoreOrdered(newValue);
00280 }
00281 
00282 // Fetch and add for pointers
00283 
00284 template <typename T>
00285 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
00286 {
00287     taskLock();
00288     T *returnValue = (_q_value);
00289     _q_value += valueToAdd;
00290     taskUnlock();
00291     return returnValue;
00292 }
00293 
00294 template <typename T>
00295 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
00296 {
00297     return fetchAndAddOrdered(valueToAdd);
00298 }
00299 
00300 template <typename T>
00301 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
00302 {
00303     return fetchAndAddOrdered(valueToAdd);
00304 }
00305 
00306 template <typename T>
00307 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
00308 {
00309     return fetchAndAddOrdered(valueToAdd);
00310 }
00311 
00312 QT_END_NAMESPACE
00313 
00314 #endif // generic implementation with taskLock()
00315 
00316 QT_END_HEADER
00317 
00318 #endif // QATOMIC_VXWORKS_H