diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-09-04 15:35:16 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-10-17 12:02:56 +0200 |
commit | d4b206b246caf9b49110526585693ab629609d99 (patch) | |
tree | 1149ccd1e50f2e5cda8dcfba09c3e3bdcfb2a2a3 /src/corelib/thread/qmutex_linux.cpp | |
parent | 77d812683f0ad595606f9833613dd49bb2fda26d (diff) |
Split QMutex and QRecursiveMutex
These classes should not inherit from each other
anymore in Qt 6. The reason is that this makes
the 95% case of using a non-recursive mutex
much slower than it has to be.
This way, QMutex can now inline the fast path
and be pretty much as fast as QBasicMutex is
in Qt 5. They actually use the same code paths
now. The main difference is that QMutex allows
calling tryLock() with a timeout, which that
is not allowed for QBasicMutex.
[ChangeLog][QtCore][QMutex] QMutex does not support
recursive locking anymore. Use QRecursiveMutex for that
purpose. QRecursiveMutex does not inherit QMutex anymore
in Qt 6.
Change-Id: I10f9bab6269a9181a2e9f534fb72ce65bc76d989
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qmutex_linux.cpp')
-rw-r--r-- | src/corelib/thread/qmutex_linux.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 72002838cf..ceb9be52a8 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -100,13 +100,13 @@ using namespace QtFutex; * waiting in the past. We then set the mutex to 0x0 and perform a FUTEX_WAKE. */ -static inline QMutexData *dummyFutexValue() +static inline QMutexPrivate *dummyFutexValue() { - return reinterpret_cast<QMutexData *>(quintptr(3)); + return reinterpret_cast<QMutexPrivate *>(quintptr(3)); } template <bool IsTimed> static inline -bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = nullptr) noexcept +bool lockInternal_helper(QBasicAtomicPointer<QMutexPrivate> &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = nullptr) noexcept { if (!IsTimed) timeout = -1; @@ -155,13 +155,11 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = - void QBasicMutex::lockInternal() noexcept { - Q_ASSERT(!isRecursive()); lockInternal_helper<false>(d_ptr); } bool QBasicMutex::lockInternal(int timeout) noexcept { - Q_ASSERT(!isRecursive()); QElapsedTimer elapsedTimer; elapsedTimer.start(); return lockInternal_helper<true>(d_ptr, timeout, &elapsedTimer); @@ -169,11 +167,10 @@ bool QBasicMutex::lockInternal(int timeout) noexcept void QBasicMutex::unlockInternal() noexcept { - QMutexData *d = d_ptr.loadRelaxed(); + QMutexPrivate *d = d_ptr.loadRelaxed(); Q_ASSERT(d); //we must be locked Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed Q_UNUSED(d); - Q_ASSERT(!isRecursive()); d_ptr.storeRelease(nullptr); futexWakeOne(d_ptr); |