From 0e681064b54a6873bef5ddb7edef7e2efc317efc Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 4 Sep 2020 10:40:29 +0200 Subject: Deprecate QMutex in recursive mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use QRecursiveMutex instead. Pick-to: 5.15 Change-Id: I862fc2b3143deeb5c96dc8d445be5f9fa2535670 Reviewed-by: Volker Hilsheimer Reviewed-by: MÃ¥rten Nordheim --- src/corelib/thread/qmutex.cpp | 4 +++- src/corelib/thread/qmutex.h | 11 ++++++++--- src/corelib/thread/qwaitcondition_unix.cpp | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 7f052feaa5..7ae07a3aa2 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -152,6 +152,7 @@ public: /*! \enum QMutex::RecursionMode + \obsolete Use QRecursiveMutex to create a recursive mutex. \value Recursive In this mode, a thread can lock the same mutex multiple times and the mutex won't be unlocked @@ -173,6 +174,7 @@ public: /*! Constructs a new mutex. The mutex is created in an unlocked state. + \obsolete Use QRecursiveMutex to create a recursive mutex. If \a mode is QMutex::Recursive, a thread can lock the same mutex multiple times and the mutex won't be unlocked until a @@ -197,7 +199,7 @@ QMutex::QMutex(RecursionMode mode) QMutex::~QMutex() { QMutexData *d = d_ptr.loadRelaxed(); - if (isRecursive()) { + if (QBasicMutex::isRecursive()) { delete static_cast(d); } else if (d) { #ifndef QT_LINUX_FUTEX diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index c1c87100e6..b29a7e3a9b 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -132,8 +132,16 @@ public: #else QMutex() { d_ptr.storeRelaxed(nullptr); } #endif +#if QT_DEPRECATED_SINCE(5,15) enum RecursionMode { NonRecursive, Recursive }; + QT_DEPRECATED_VERSION_X(5, 15, "Use QRecursiveMutex instead of a recursive QMutex") explicit QMutex(RecursionMode mode); + + QT_DEPRECATED_VERSION_X(5, 15, "Use QRecursiveMutex instead of a recursive QMutex") + bool isRecursive() const noexcept + { return QBasicMutex::isRecursive(); } +#endif + ~QMutex(); // BasicLockable concept @@ -164,9 +172,6 @@ public: } #endif - bool isRecursive() const noexcept - { return QBasicMutex::isRecursive(); } - private: Q_DISABLE_COPY(QMutex) friend class QMutexLocker; diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index a1c973562b..4dbd774428 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -213,7 +213,7 @@ bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline) { if (! mutex) return false; - if (mutex->isRecursive()) { + if (static_cast(mutex)->isRecursive()) { qWarning("QWaitCondition: cannot wait on recursive mutexes"); return false; } -- cgit v1.2.3