QtCore/qmutex.h Source File
Go to the documentation of this file.
63 friend class QWaitConditionPrivate;
68 explicit QMutex(RecursionMode
mode = NonRecursive);
72 inline void lockInline();
74 bool tryLock(
int timeout);
75 inline bool tryLockInline();
77 inline void unlockInline();
79 #if defined(QT3_SUPPORT)
80 inline QT3_SUPPORT
bool locked()
87 inline QT3_SUPPORT_CONSTRUCTOR
QMutex(
bool recursive)
89 new (
this)
QMutex(recursive ? Recursive : NonRecursive);
95 void unlockInternal();
106 Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0),
107 "QMutexLocker",
"QMutex pointer is misaligned");
110 val =
reinterpret_cast<quintptr
>(m) | quintptr(1u);
119 if ((val & quintptr(1u)) == quintptr(1u)) {
120 val &= ~quintptr(1u);
121 mutex()->unlockInline();
128 if ((val & quintptr(1u)) == quintptr(0u)) {
129 mutex()->lockInline();
135 #if defined(Q_CC_MSVC)
136 #pragma warning( push )
137 #pragma warning( disable : 4312 ) // ignoring the warning from /Wp64
142 return reinterpret_cast<QMutex *
>(val & ~quintptr(1u));
145 #if defined(Q_CC_MSVC)
146 #pragma warning( pop )
150 Q_DISABLE_COPY(QMutexLocker)
159 const uint recursive : 1;
171 }
else if (!d->contenders.testAndSetRelease(1, 0)) {
181 return d->contenders.testAndSetAcquire(0, 1);
189 }
else if(!tryLockInline()) {
199 #endif // QT_NO_DEBUG
202 #else // QT_NO_THREAD
205 class Q_CORE_EXPORT
QMutex
208 enum RecursionMode { NonRecursive, Recursive };
210 inline explicit QMutex(RecursionMode
mode = NonRecursive) { Q_UNUSED(
mode); }
213 static inline void lock() {}
214 static inline void lockInline() {}
215 static inline bool tryLock(
int timeout = 0) { Q_UNUSED(timeout);
return true; }
216 static inline bool tryLockInline() {
return true; }
217 static inline void unlock() {}
218 static inline void unlockInline() {}
220 #if defined(QT3_SUPPORT)
221 static inline QT3_SUPPORT
bool locked() {
return false; }
228 class Q_CORE_EXPORT QMutexLocker
231 inline explicit QMutexLocker(
QMutex *) {}
232 inline ~QMutexLocker() {}
234 static inline void unlock() {}
235 static void relock() {}
236 static inline QMutex *mutex() {
return 0; }
239 Q_DISABLE_COPY(QMutexLocker)
242 #endif // QT_NO_THREAD
#define QT_BEGIN_NAMESPACE