From 08ad96404b4c915eece1a547bf12e91664e7cdff Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Aug 2019 22:14:16 +0200 Subject: QCoreApplication: work towards replacing a QRecursiveMutex with a QMutex At first glance, libraryPathMutex is only recursive because setLibraryPaths(), addLibraryPath() and removeLibraryPath(), all of which lock libraryPathMutex, may call libraryPaths(), which does, too. This is easily fixed by splitting libraryPaths() into public libraryPaths() and private libraryPathsLocked(), the latter expecting to be called with the libraryPathMutex already held. And this is what this patch does. However, on second glance, the building of the initial app_libpaths calls a monstrous amount of code, incl. QLibraryInfo, and some of that code probably re-enters one of the library-path functions. So while this patch is a step towards making libraryPathMutex non-recursive, it's probably not the end. Change-Id: I3ed83272ace6966980cf8e1db877f24c89789da3 Reviewed-by: Ulf Hermann Reviewed-by: Edward Welbourne Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qcoreapplication.cpp | 13 ++++++++++--- src/corelib/kernel/qcoreapplication.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 6647ea99f5..c537e8f51b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2693,7 +2693,14 @@ Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex) QStringList QCoreApplication::libraryPaths() { QMutexLocker locker(libraryPathMutex()); + return libraryPathsLocked(); +} +/*! + \internal +*/ +QStringList QCoreApplication::libraryPathsLocked() +{ if (coreappdata()->manual_libpaths) return *(coreappdata()->manual_libpaths); @@ -2769,7 +2776,7 @@ void QCoreApplication::setLibraryPaths(const QStringList &paths) // When the application is constructed it should still amend the paths. So we keep the originals // around, and even create them if they don't exist, yet. if (!coreappdata()->app_libpaths) - libraryPaths(); + libraryPathsLocked(); if (coreappdata()->manual_libpaths) *(coreappdata()->manual_libpaths) = paths; @@ -2812,7 +2819,7 @@ void QCoreApplication::addLibraryPath(const QString &path) return; } else { // make sure that library paths are initialized - libraryPaths(); + libraryPathsLocked(); QStringList *app_libpaths = coreappdata()->app_libpaths.data(); if (app_libpaths->contains(canonicalPath)) return; @@ -2851,7 +2858,7 @@ void QCoreApplication::removeLibraryPath(const QString &path) return; } else { // make sure that library paths is initialized - libraryPaths(); + libraryPathsLocked(); QStringList *app_libpaths = coreappdata()->app_libpaths.data(); if (!app_libpaths->contains(canonicalPath)) return; diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index b7df004736..71ea124fbe 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -208,6 +208,9 @@ private: static bool notifyInternal2(QObject *receiver, QEvent *); static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr); #endif +#if QT_CONFIG(library) + static QStringList libraryPathsLocked(); +#endif static QCoreApplication *self; -- cgit v1.2.3 From 351c738fc4586bf354c9363fb78e190bdfca4617 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Sep 2019 11:07:31 +0200 Subject: QPointer: some simplifications - don't write explicit meta functions, use std::conditional - = default the default ctor The class is already not trivially-copyable, so making the default ctor trivial doesn't change the ABI. Change-Id: I8e35bbbb35973c9ff8fc48dfbfc10061de4bfd30 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qpointer.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index 7052bcf0d4..5efdb0b395 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -54,20 +54,11 @@ class QPointer { Q_STATIC_ASSERT_X(!std::is_pointer::value, "QPointer's template type must not be a pointer type"); - template - struct TypeSelector - { - typedef QObject Type; - }; - template - struct TypeSelector - { - typedef const QObject Type; - }; - typedef typename TypeSelector::Type QObjectType; + using QObjectType = + typename std::conditional::value, const QObject, QObject>::type; QWeakPointer wp; public: - inline QPointer() { } + QPointer() = default; inline QPointer(T *p) : wp(p, true) { } // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated dtor is fine! -- cgit v1.2.3