Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QATOMIC_H
00043 #define QATOMIC_H
00044
00045 #include <QtCore/qglobal.h>
00046 #include <QtCore/qbasicatomic.h>
00047
00048 QT_BEGIN_HEADER
00049
00050 QT_BEGIN_NAMESPACE
00051
00052 QT_MODULE(Core)
00053
00054
00055 class Q_CORE_EXPORT QAtomicInt : public QBasicAtomicInt
00056 {
00057 public:
00058 inline QAtomicInt(int value = 0)
00059 {
00060 #ifdef QT_ARCH_PARISC
00061 this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
00062 #endif
00063 _q_value = value;
00064 }
00065 inline QAtomicInt(const QAtomicInt &other)
00066 {
00067 #ifdef QT_ARCH_PARISC
00068 this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
00069 #endif
00070 _q_value = other._q_value;
00071 }
00072
00073 inline QAtomicInt &operator=(int value)
00074 {
00075 (void) QBasicAtomicInt::operator=(value);
00076 return *this;
00077 }
00078
00079 inline QAtomicInt &operator=(const QAtomicInt &other)
00080 {
00081 (void) QBasicAtomicInt::operator=(other);
00082 return *this;
00083 }
00084
00085 #ifdef qdoc
00086 bool operator==(int value) const;
00087 bool operator!=(int value) const;
00088 bool operator!() const;
00089 operator int() const;
00090
00091 static bool isReferenceCountingNative();
00092 static bool isReferenceCountingWaitFree();
00093
00094 bool ref();
00095 bool deref();
00096
00097 static bool isTestAndSetNative();
00098 static bool isTestAndSetWaitFree();
00099
00100 bool testAndSetRelaxed(int expectedValue, int newValue);
00101 bool testAndSetAcquire(int expectedValue, int newValue);
00102 bool testAndSetRelease(int expectedValue, int newValue);
00103 bool testAndSetOrdered(int expectedValue, int newValue);
00104
00105 static bool isFetchAndStoreNative();
00106 static bool isFetchAndStoreWaitFree();
00107
00108 int fetchAndStoreRelaxed(int newValue);
00109 int fetchAndStoreAcquire(int newValue);
00110 int fetchAndStoreRelease(int newValue);
00111 int fetchAndStoreOrdered(int newValue);
00112
00113 static bool isFetchAndAddNative();
00114 static bool isFetchAndAddWaitFree();
00115
00116 int fetchAndAddRelaxed(int valueToAdd);
00117 int fetchAndAddAcquire(int valueToAdd);
00118 int fetchAndAddRelease(int valueToAdd);
00119 int fetchAndAddOrdered(int valueToAdd);
00120 #endif
00121 };
00122
00123
00124 template <typename T>
00125 class QAtomicPointer : public QBasicAtomicPointer<T>
00126 {
00127 public:
00128 inline QAtomicPointer(T *value = 0)
00129 {
00130 #ifdef QT_ARCH_PARISC
00131 this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
00132 #endif
00133 QBasicAtomicPointer<T>::_q_value = value;
00134 }
00135 inline QAtomicPointer(const QAtomicPointer<T> &other)
00136 {
00137 #ifdef QT_ARCH_PARISC
00138 this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1;
00139 #endif
00140 QBasicAtomicPointer<T>::_q_value = other._q_value;
00141 }
00142
00143 inline QAtomicPointer<T> &operator=(T *value)
00144 {
00145 (void) QBasicAtomicPointer<T>::operator=(value);
00146 return *this;
00147 }
00148
00149 inline QAtomicPointer<T> &operator=(const QAtomicPointer<T> &other)
00150 {
00151 (void) QBasicAtomicPointer<T>::operator=(other);
00152 return *this;
00153 }
00154
00155 #ifdef qdoc
00156 bool operator==(T *value) const;
00157 bool operator!=(T *value) const;
00158 bool operator!() const;
00159 operator T *() const;
00160 T *operator->() const;
00161
00162 static bool isTestAndSetNative();
00163 static bool isTestAndSetWaitFree();
00164
00165 bool testAndSetRelaxed(T *expectedValue, T *newValue);
00166 bool testAndSetAcquire(T *expectedValue, T *newValue);
00167 bool testAndSetRelease(T *expectedValue, T *newValue);
00168 bool testAndSetOrdered(T *expectedValue, T *newValue);
00169
00170 static bool isFetchAndStoreNative();
00171 static bool isFetchAndStoreWaitFree();
00172
00173 T *fetchAndStoreRelaxed(T *newValue);
00174 T *fetchAndStoreAcquire(T *newValue);
00175 T *fetchAndStoreRelease(T *newValue);
00176 T *fetchAndStoreOrdered(T *newValue);
00177
00178 static bool isFetchAndAddNative();
00179 static bool isFetchAndAddWaitFree();
00180
00181 T *fetchAndAddRelaxed(qptrdiff valueToAdd);
00182 T *fetchAndAddAcquire(qptrdiff valueToAdd);
00183 T *fetchAndAddRelease(qptrdiff valueToAdd);
00184 T *fetchAndAddOrdered(qptrdiff valueToAdd);
00185 #endif
00186 };
00187
00194 template <typename T>
00195 inline void qAtomicAssign(T *&d, T *x)
00196 {
00197 if (d == x)
00198 return;
00199 x->ref.ref();
00200 if (!d->ref.deref())
00201 delete d;
00202 d = x;
00203 }
00204
00213 template <typename T>
00214 inline void qAtomicDetach(T *&d)
00215 {
00216 if (d->ref == 1)
00217 return;
00218 T *x = d;
00219 d = new T(*d);
00220 if (!x->ref.deref())
00221 delete x;
00222 }
00223
00224 QT_END_NAMESPACE
00225 QT_END_HEADER
00226
00227 #endif // QATOMIC_H