QCoreApplication: move the QRecursiveMutex into QCoreApplicationData

There's no need for it to be a global, if the data isn't either. I have
a vague recollection of the data also being globals back in the
day... (they used to be plain QStringList pointers).

Pick-to: 6.9
Change-Id: Ie5f1a71d0b20a0195822fffd992101c94824a07f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Thiago Macieira 2025-01-07 10:12:29 -03:00
parent 9fe44e4779
commit a314e4b985

View File

@ -384,6 +384,7 @@ struct QCoreApplicationData
#if QT_CONFIG(library)
std::unique_ptr<QStringList> app_libpaths;
std::unique_ptr<QStringList> manual_libpaths;
QRecursiveMutex libraryPathMutex; // protects this block
#endif
};
@ -2921,9 +2922,6 @@ void QCoreApplication::requestPermission(const QPermission &requestedPermission,
#endif // QT_CONFIG(permissions)
#if QT_CONFIG(library)
Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex)
/*!
Returns a list of paths that the application will search when
dynamically loading libraries.
@ -2955,7 +2953,7 @@ Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex)
*/
QStringList QCoreApplication::libraryPaths()
{
QMutexLocker locker(libraryPathMutex());
QMutexLocker locker(&coreappdata->libraryPathMutex);
return libraryPathsLocked();
}
@ -3035,7 +3033,8 @@ QStringList QCoreApplication::libraryPathsLocked()
*/
void QCoreApplication::setLibraryPaths(const QStringList &paths)
{
QMutexLocker locker(libraryPathMutex());
QCoreApplicationData *d = coreappdata;
QMutexLocker locker(&d->libraryPathMutex);
// setLibraryPaths() is considered a "remove everything and then add some new ones" operation.
// When the application is constructed it should still amend the paths. So we keep the originals
@ -3077,7 +3076,8 @@ void QCoreApplication::addLibraryPath(const QString &path)
if (canonicalPath.isEmpty())
return;
QMutexLocker locker(libraryPathMutex());
QCoreApplicationData *d = coreappdata;
QMutexLocker locker(&d->libraryPathMutex);
QStringList *libpaths = coreappdata()->manual_libpaths.get();
if (libpaths) {
@ -3116,7 +3116,8 @@ void QCoreApplication::removeLibraryPath(const QString &path)
if (canonicalPath.isEmpty())
return;
QMutexLocker locker(libraryPathMutex());
QCoreApplicationData *d = coreappdata;
QMutexLocker locker(&d->libraryPathMutex);
QStringList *libpaths = coreappdata()->manual_libpaths.get();
if (libpaths) {