From b19deae0c0abd313dcc85a51927a461be4e2818e Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 21 Jul 2021 17:04:22 +0300 Subject: [PATCH 1/6] solid: make string translation consistent in Solid::errorString() Signed-off-by: Ivailo Monev --- solid/solid/solidnamespace.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/solid/solid/solidnamespace.cpp b/solid/solid/solidnamespace.cpp index 69205456..c90a1344 100644 --- a/solid/solid/solidnamespace.cpp +++ b/solid/solid/solidnamespace.cpp @@ -19,12 +19,10 @@ */ #include "solidnamespace.h" -#include "klocale.h" static int registerSolidMetaTypes() { qRegisterMetaType(); - return 0; // something } Q_CONSTRUCTOR_FUNCTION(registerSolidMetaTypes) @@ -35,17 +33,17 @@ QString Solid::errorString(const ErrorType error) case Solid::NoError: return QString(); case Solid::UnauthorizedOperation: - return i18n("Unauthorized operation"); + return QObject::tr("Unauthorized operation"); case Solid::DeviceBusy: - return i18n("Device is busy"); + return QObject::tr("Device is busy"); case Solid::OperationFailed: - return i18n("Operation failed"); + return QObject::tr("Operation failed"); case Solid::UserCanceled: - return i18n("Canceled by user"); + return QObject::tr("Canceled by user"); case Solid::InvalidOption: - return i18n("Invalid option"); + return QObject::tr("Invalid option"); case Solid::MissingDriver: - return i18n("Missing driver"); + return QObject::tr("Missing driver"); } return QString(); } From e5cd3bbfc76ef11a9a6b519c7e1f78deca222d18 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 21 Jul 2021 22:34:22 +0300 Subject: [PATCH 2/6] plasma: replace read-write locks with mutexes where possible Signed-off-by: Ivailo Monev --- plasma/abstractrunner.cpp | 14 ++------------ plasma/private/abstractrunner_p.h | 4 ++-- plasma/querymatch.cpp | 28 +++++++++++----------------- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/plasma/abstractrunner.cpp b/plasma/abstractrunner.cpp index ac5ecf22..bd458cf6 100644 --- a/plasma/abstractrunner.cpp +++ b/plasma/abstractrunner.cpp @@ -211,23 +211,13 @@ void AbstractRunner::createRunOptions(QWidget *parent) AbstractRunner::Speed AbstractRunner::speed() const { - // the only time the read lock will fail is if we were slow are going to speed up - // or if we were fast and are going to slow down; so don't wait in this case, just - // say we're slow. we either will be soon or were just a moment ago and it doesn't - // hurt to do one more run the slow way - if (!d->speedLock.tryLockForRead()) { - return SlowSpeed; - } - Speed s = d->speed; - d->speedLock.unlock(); - return s; + return d->speed; } void AbstractRunner::setSpeed(Speed speed) { - d->speedLock.lockForWrite(); + QMutexLocker locker(&d->speedMutex); d->speed = speed; - d->speedLock.unlock(); } AbstractRunner::Priority AbstractRunner::priority() const diff --git a/plasma/private/abstractrunner_p.h b/plasma/private/abstractrunner_p.h index 337feb4b..731ebe18 100644 --- a/plasma/private/abstractrunner_p.h +++ b/plasma/private/abstractrunner_p.h @@ -20,7 +20,7 @@ #ifndef ABSTRACTRUNNER_P_H #define ABSTRACTRUNNER_P_H -#include +#include #include "dataengineconsumer_p.h" @@ -42,7 +42,7 @@ public: KPluginInfo runnerDescription; AbstractRunner *runner; int fastRuns; - QReadWriteLock speedLock; + QMutex speedMutex; QHash actions; QList syntaxes; RunnerSyntax *defaultSyntax; diff --git a/plasma/querymatch.cpp b/plasma/querymatch.cpp index c134aa4e..86788bcf 100644 --- a/plasma/querymatch.cpp +++ b/plasma/querymatch.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ class QueryMatchPrivate : public QSharedData public: QueryMatchPrivate(AbstractRunner *r) : QSharedData(), - lock(new QReadWriteLock(QReadWriteLock::Recursive)), + mutex(new QMutex(QMutex::Recursive)), runner(r), type(QueryMatch::ExactMatch), relevance(.7), @@ -51,9 +51,9 @@ class QueryMatchPrivate : public QSharedData QueryMatchPrivate(const QueryMatchPrivate &other) : QSharedData(other), - lock(new QReadWriteLock(QReadWriteLock::Recursive)) + mutex(new QMutex(QMutex::Recursive)) { - QReadLocker lock(other.lock); + QMutexLocker lock(other.mutex); runner = other.runner; type = other.type; relevance = other.relevance; @@ -69,10 +69,10 @@ class QueryMatchPrivate : public QSharedData ~QueryMatchPrivate() { - delete lock; + delete mutex; } - QReadWriteLock *lock; + QMutex *mutex; QWeakPointer runner; QueryMatch::Type type; QString id; @@ -142,19 +142,19 @@ AbstractRunner* QueryMatch::runner() const void QueryMatch::setText(const QString &text) { - QWriteLocker locker(d->lock); + QMutexLocker locker(d->mutex); d->text = text; } void QueryMatch::setSubtext(const QString &subtext) { - QWriteLocker locker(d->lock); + QMutexLocker locker(d->mutex); d->subtext = subtext; } void QueryMatch::setData(const QVariant & data) { - QWriteLocker locker(d->lock); + QMutexLocker locker(d->mutex); d->data = data; if (d->id.isEmpty() || d->idSetByData) { @@ -168,7 +168,7 @@ void QueryMatch::setData(const QVariant & data) void QueryMatch::setId(const QString &id) { - QWriteLocker locker(d->lock); + QMutexLocker locker(d->mutex); if (d->runner) { d->id = d->runner.data()->id(); } @@ -182,31 +182,27 @@ void QueryMatch::setId(const QString &id) void QueryMatch::setIcon(const QIcon &icon) { - QWriteLocker locker(d->lock); + QMutexLocker locker(d->mutex); d->icon = icon; } QVariant QueryMatch::data() const { - QReadLocker locker(d->lock); return d->data; } QString QueryMatch::text() const { - QReadLocker locker(d->lock); return d->text; } QString QueryMatch::subtext() const { - QReadLocker locker(d->lock); return d->subtext; } QIcon QueryMatch::icon() const { - QReadLocker locker(d->lock); return d->icon; } @@ -241,8 +237,6 @@ bool QueryMatch::operator<(const QueryMatch &other) const return d->relevance < other.d->relevance; } - QReadLocker locker(d->lock); - QReadLocker otherLocker(other.d->lock); // when resorting to sort by alpha, we want the // reverse sort order! return d->text > other.d->text; From a8f4cd469cd4a739fb9e8fcb4081405a03f96a09 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 21 Jul 2021 22:57:41 +0300 Subject: [PATCH 3/6] kio: don't lookup for bookmark manager twice Signed-off-by: Ivailo Monev --- kio/bookmarks/kbookmarkmanager.cc | 34 ++++++++----------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/kio/bookmarks/kbookmarkmanager.cc b/kio/bookmarks/kbookmarkmanager.cc index 0fcac614..06f69835 100644 --- a/kio/bookmarks/kbookmarkmanager.cc +++ b/kio/bookmarks/kbookmarkmanager.cc @@ -27,9 +27,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -57,7 +57,7 @@ public: qDeleteAll( begin() , end() ); // auto-delete functionality } - QReadWriteLock lock; + QMutex mutex; }; K_GLOBAL_STATIC(KBookmarkManagerList, s_pSelf) @@ -162,17 +162,8 @@ static KBookmarkManager* lookupExisting(const QString& bookmarksFile) KBookmarkManager* KBookmarkManager::managerForFile( const QString& bookmarksFile, const QString& dbusObjectName ) { - KBookmarkManager* mgr(0); - { - QReadLocker readLock(&s_pSelf->lock); - mgr = lookupExisting(bookmarksFile); - if (mgr) { - return mgr; - } - } - - QWriteLocker writeLock(&s_pSelf->lock); - mgr = lookupExisting(bookmarksFile); + QMutexLocker lock(&s_pSelf->mutex); + KBookmarkManager* mgr = lookupExisting(bookmarksFile); if (mgr) { return mgr; } @@ -184,17 +175,8 @@ KBookmarkManager* KBookmarkManager::managerForFile( const QString& bookmarksFile KBookmarkManager* KBookmarkManager::managerForExternalFile( const QString& bookmarksFile ) { - KBookmarkManager* mgr(0); - { - QReadLocker readLock(&s_pSelf->lock); - mgr = lookupExisting(bookmarksFile); - if (mgr) { - return mgr; - } - } - - QWriteLocker writeLock(&s_pSelf->lock); - mgr = lookupExisting(bookmarksFile); + QMutexLocker lock(&s_pSelf->mutex); + KBookmarkManager* mgr = lookupExisting(bookmarksFile); if (mgr) { return mgr; } From 4b0b6cbe6ae966c3c72325c334f961fc1ca81695 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 21 Jul 2021 23:12:37 +0300 Subject: [PATCH 4/6] kdecore: replace read-write lock with mutex in KMimeTypeRepository Signed-off-by: Ivailo Monev --- kdecore/services/kmimetyperepository.cpp | 24 ++++++++++++------------ kdecore/services/kmimetyperepository_p.h | 5 +++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/kdecore/services/kmimetyperepository.cpp b/kdecore/services/kmimetyperepository.cpp index 0c492345..e74a1fe3 100644 --- a/kdecore/services/kmimetyperepository.cpp +++ b/kdecore/services/kmimetyperepository.cpp @@ -50,7 +50,7 @@ KMimeTypeRepository::KMimeTypeRepository() m_useFavIcons(true), m_useFavIconsChecked(false), m_sharedMimeInfoVersion(0), - m_mutex(QReadWriteLock::Recursive) + m_mutex(QMutex::Recursive) { } @@ -195,7 +195,7 @@ QStringList KMimeTypeRepository::findFromFileName(const QString &fileName, QStri { parseGlobs(); - QReadLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); // First try the high weight matches (>50), if any. QStringList matchingMimeTypes; QString foundExt; @@ -248,7 +248,7 @@ KMimeType::Ptr KMimeTypeRepository::findFromContent(QIODevice* device, int* accu // Apply magic rules { - QReadLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); Q_FOREACH ( const KMimeMagicRule& rule, m_magicRules ) { if (rule.match(device, deviceSize, beginning)) { if (accuracy) @@ -288,7 +288,7 @@ static QString fallbackParent(const QString& mimeTypeName) QStringList KMimeTypeRepository::parents(const QString& mime) { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (!m_parentsMapLoaded) { m_parentsMapLoaded = true; Q_ASSERT(m_parents.isEmpty()); @@ -345,7 +345,7 @@ static bool mimeMagicRuleCompare(const KMimeMagicRule& lhs, const KMimeMagicRule void KMimeTypeRepository::parseMagic() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (m_magicFilesParsed) { return; } @@ -549,7 +549,7 @@ QList KMimeTypeRepository::parseMagicFile(QIODevice* file, const const KMimeTypeRepository::AliasesMap& KMimeTypeRepository::aliases() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (m_aliasFilesParsed) { return m_aliases; } @@ -589,7 +589,7 @@ const KMimeTypeRepository::AliasesMap& KMimeTypeRepository::aliases() void KMimeTypeRepository::parseGlobs() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (m_globsFilesParsed) { return; } @@ -603,7 +603,7 @@ QStringList KMimeTypeRepository::patternsForMimetype(const QString& mimeType) { parseGlobs(); - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (!m_patternsMapCalculated) { m_patternsMapCalculated = true; m_patterns = m_globs.patternsMap(); @@ -619,7 +619,7 @@ static void errorMissingMimeTypes( const QStringList& _types ) void KMimeTypeRepository::checkEssentialMimeTypes() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (m_mimeTypesChecked) { // already done return; } @@ -663,7 +663,7 @@ void KMimeTypeRepository::checkEssentialMimeTypes() KMimeType::Ptr KMimeTypeRepository::defaultMimeTypePtr() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (!m_defaultMimeType) { // Try to find the default type KMimeType::Ptr mime = findMimeTypeByName(KMimeType::defaultMimeType()); @@ -684,7 +684,7 @@ bool KMimeTypeRepository::useFavIcons() { // this method will be called quite often, so better not read the config // again and again. - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (!m_useFavIconsChecked) { m_useFavIconsChecked = true; KConfigGroup cg( KGlobal::config(), "HTML Settings" ); @@ -783,7 +783,7 @@ static int mimeDataBaseVersion() int KMimeTypeRepository::sharedMimeInfoVersion() { - QWriteLocker lock(&m_mutex); + QMutexLocker lock(&m_mutex); if (m_sharedMimeInfoVersion == 0) m_sharedMimeInfoVersion = mimeDataBaseVersion(); return m_sharedMimeInfoVersion; diff --git a/kdecore/services/kmimetyperepository_p.h b/kdecore/services/kmimetyperepository_p.h index e1d2389a..0f2fdc9e 100644 --- a/kdecore/services/kmimetyperepository_p.h +++ b/kdecore/services/kmimetyperepository_p.h @@ -24,7 +24,8 @@ #include "kmimemagicrule_p.h" #include "kmimeglobsfileparser_p.h" #include "kmimetype.h" -#include + +#include /** * @internal - this header is not installed @@ -172,7 +173,7 @@ private: QList m_magicRules; KMimeGlobsFileParser::AllGlobs m_globs; KMimeType::Ptr m_defaultMimeType; - QReadWriteLock m_mutex; + QMutex m_mutex; }; #endif /* KMIMETYPEREPOSITORY_H */ From ebf69fb68e75b9d954c210f3775b1ff35ac5a545 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 22 Jul 2021 01:24:13 +0300 Subject: [PATCH 5/6] generic: replace recursive QMutex-es with std::recursive_mutex-es [ci reset] Signed-off-by: Ivailo Monev --- kdecore/kernel/kstandarddirs.cpp | 10 +++--- kdecore/localization/klocale_kde.cpp | 29 ++++++++-------- kdecore/localization/klocale_p.h | 4 +-- kdecore/localization/klocalizedstring.cpp | 2 +- kdecore/services/kmimetyperepository.cpp | 25 +++++++------- kdecore/services/kmimetyperepository_p.h | 4 +-- plasma/querymatch.cpp | 25 +++++++------- threadweaver/Weaver/WeaverImpl.cpp | 40 +++++++++++------------ threadweaver/Weaver/WeaverImpl.h | 4 ++- 9 files changed, 70 insertions(+), 73 deletions(-) diff --git a/kdecore/kernel/kstandarddirs.cpp b/kdecore/kernel/kstandarddirs.cpp index de761eba..f60d9440 100644 --- a/kdecore/kernel/kstandarddirs.cpp +++ b/kdecore/kernel/kstandarddirs.cpp @@ -53,7 +53,6 @@ #include #include -#include #include #include #include @@ -61,6 +60,8 @@ #include #include +#include + #define case_sensitivity Qt::CaseSensitive #ifndef PATH_MAX @@ -73,7 +74,6 @@ public: KStandardDirsPrivate(KStandardDirs* qq) : m_restrictionsActive(false), m_checkRestrictions(true), - m_cacheMutex(QMutex::Recursive), // resourceDirs is recursive q(qq) { } @@ -99,7 +99,7 @@ public: // Caches (protected by mutex in const methods, cf ctor docu) QMap m_dircache; QMap m_savelocations; - QMutex m_cacheMutex; + std::recursive_mutex m_cacheMutex; // resourceDirs is recursive KStandardDirs* q; }; @@ -917,7 +917,7 @@ QStringList KStandardDirs::resourceDirs(const char *type) const QStringList KStandardDirs::KStandardDirsPrivate::resourceDirs(const char* type, const QString& subdirForRestrictions) { - QMutexLocker lock(&m_cacheMutex); + std::lock_guard lock(m_cacheMutex); const bool dataRestrictionActive = m_restrictionsActive && (strcmp(type, "data") == 0) && hasDataRestrictions(subdirForRestrictions); @@ -1226,7 +1226,7 @@ QString KStandardDirs::saveLocation(const char *type, const QString& suffix, bool create) const { - QMutexLocker lock(&d->m_cacheMutex); + std::lock_guard lock(d->m_cacheMutex); QString path = d->m_savelocations.value(type); if (path.isEmpty()) { diff --git a/kdecore/localization/klocale_kde.cpp b/kdecore/localization/klocale_kde.cpp index 33bd5661..30efd391 100644 --- a/kdecore/localization/klocale_kde.cpp +++ b/kdecore/localization/klocale_kde.cpp @@ -41,9 +41,10 @@ #include #include #include -#include #include +#include + #include "kcatalog_p.h" #include "kglobal.h" #include "kstandarddirs.h" @@ -307,7 +308,7 @@ void KLocalePrivate::initConfig(KConfig *config) void KLocalePrivate::initMainCatalogs() { KLocaleStaticData *s = staticData; - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); if (!s->maincatalog.isEmpty()) { // If setMainCatalog was called, then we use that @@ -629,7 +630,7 @@ bool KLocalePrivate::setCountryDivisionCode(const QString &countryDivisionCode) bool KLocalePrivate::setLanguage(const QString &language, KConfig *config) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); m_languageList.removeAll(language); m_languageList.prepend(language); // let us consider this language to be the most important one @@ -655,7 +656,7 @@ bool KLocalePrivate::setLanguage(const QString &language, KConfig *config) // config so this can be reparsed when required. bool KLocalePrivate::setLanguage(const QStringList &languages) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); // This list might contain // 1) some empty strings that we have to eliminate // 2) duplicate entries like in de:fr:de, where we have to keep the first occurrence of a @@ -806,7 +807,7 @@ QString KLocalePrivate::currencyCode() const void KLocalePrivate::insertCatalog(const QString &catalog) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); int pos = m_catalogNames.indexOf(KCatalogName(catalog)); if (pos != -1) { ++m_catalogNames[pos].loadCount; @@ -855,7 +856,7 @@ void KLocalePrivate::updateCatalogs() void KLocalePrivate::removeCatalog(const QString &catalog) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); int pos = m_catalogNames.indexOf(KCatalogName(catalog)); if (pos == -1) { return; @@ -872,7 +873,7 @@ void KLocalePrivate::removeCatalog(const QString &catalog) void KLocalePrivate::setActiveCatalog(const QString &catalog) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); int pos = m_catalogNames.indexOf(KCatalogName(catalog)); if (pos == -1) { return; @@ -901,7 +902,7 @@ void KLocalePrivate::translateRawFrom(const char *catname, const char *msgctxt, << "Fix the program" << endl; } - QMutexLocker locker(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); // determine the fallback string QString fallback; if (msgid_plural == NULL) { @@ -1702,7 +1703,7 @@ QString KLocalePrivate::formatByteSize(double size, int precision, KLocale::Bina if (dialect == m_binaryUnitDialect) { // Cache default units for speed if (m_byteSizeFmt.size() == 0) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); // We only cache the user's default dialect. m_byteSizeFmt = dialectUnitsList(m_binaryUnitDialect); @@ -1756,7 +1757,7 @@ KLocale::BinaryUnitDialect KLocalePrivate::binaryUnitDialect() const void KLocalePrivate::setBinaryUnitDialect(KLocale::BinaryUnitDialect newDialect) { if (newDialect > KLocale::DefaultBinaryDialect && newDialect <= KLocale::LastBinaryDialect) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); m_binaryUnitDialect = newDialect; m_byteSizeFmt.clear(); // Reset cached translations. } @@ -3029,7 +3030,7 @@ KLocale::WeekNumberSystem KLocalePrivate::weekNumberSystem() const void KLocalePrivate::copyCatalogsTo(KLocale *locale) { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); locale->d->m_catalogNames = m_catalogNames; locale->d->updateCatalogs(); } @@ -3102,9 +3103,9 @@ KLocale::DigitSet KLocalePrivate::dateTimeDigitSet() const return m_dateTimeDigitSet; } -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, s_kLocaleMutex, (QMutex::Recursive)) +static std::recursive_mutex s_kLocaleMutex; -QMutex *kLocaleMutex() +std::recursive_mutex& kLocaleMutex() { - return s_kLocaleMutex(); + return s_kLocaleMutex; } diff --git a/kdecore/localization/klocale_p.h b/kdecore/localization/klocale_p.h index 0bd60182..53478fff 100644 --- a/kdecore/localization/klocale_p.h +++ b/kdecore/localization/klocale_p.h @@ -24,12 +24,12 @@ #include "klocale.h" #include "kdayperiod_p.h" -#include +#include class KCatalog; // Used by both KLocale and KLocalizedString, since they call each other. -QMutex* kLocaleMutex(); +std::recursive_mutex& kLocaleMutex(); class KLocalePrivate { diff --git a/kdecore/localization/klocalizedstring.cpp b/kdecore/localization/klocalizedstring.cpp index c993ec32..7519b846 100644 --- a/kdecore/localization/klocalizedstring.cpp +++ b/kdecore/localization/klocalizedstring.cpp @@ -159,7 +159,7 @@ QString KLocalizedString::toString (const KLocale *locale, QString KLocalizedStringPrivate::toString (const KLocale *locale, const QString *catalogName) const { - QMutexLocker lock(kLocaleMutex()); + std::lock_guard lock(kLocaleMutex()); // Assure the message has been supplied. if (msg.isEmpty()) diff --git a/kdecore/services/kmimetyperepository.cpp b/kdecore/services/kmimetyperepository.cpp index e74a1fe3..aadebe9d 100644 --- a/kdecore/services/kmimetyperepository.cpp +++ b/kdecore/services/kmimetyperepository.cpp @@ -49,8 +49,7 @@ KMimeTypeRepository::KMimeTypeRepository() m_mimeTypesChecked(false), m_useFavIcons(true), m_useFavIconsChecked(false), - m_sharedMimeInfoVersion(0), - m_mutex(QMutex::Recursive) + m_sharedMimeInfoVersion(0) { } @@ -195,7 +194,7 @@ QStringList KMimeTypeRepository::findFromFileName(const QString &fileName, QStri { parseGlobs(); - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); // First try the high weight matches (>50), if any. QStringList matchingMimeTypes; QString foundExt; @@ -248,7 +247,7 @@ KMimeType::Ptr KMimeTypeRepository::findFromContent(QIODevice* device, int* accu // Apply magic rules { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); Q_FOREACH ( const KMimeMagicRule& rule, m_magicRules ) { if (rule.match(device, deviceSize, beginning)) { if (accuracy) @@ -288,7 +287,7 @@ static QString fallbackParent(const QString& mimeTypeName) QStringList KMimeTypeRepository::parents(const QString& mime) { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (!m_parentsMapLoaded) { m_parentsMapLoaded = true; Q_ASSERT(m_parents.isEmpty()); @@ -345,7 +344,7 @@ static bool mimeMagicRuleCompare(const KMimeMagicRule& lhs, const KMimeMagicRule void KMimeTypeRepository::parseMagic() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (m_magicFilesParsed) { return; } @@ -549,7 +548,7 @@ QList KMimeTypeRepository::parseMagicFile(QIODevice* file, const const KMimeTypeRepository::AliasesMap& KMimeTypeRepository::aliases() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (m_aliasFilesParsed) { return m_aliases; } @@ -589,7 +588,7 @@ const KMimeTypeRepository::AliasesMap& KMimeTypeRepository::aliases() void KMimeTypeRepository::parseGlobs() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (m_globsFilesParsed) { return; } @@ -603,7 +602,7 @@ QStringList KMimeTypeRepository::patternsForMimetype(const QString& mimeType) { parseGlobs(); - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (!m_patternsMapCalculated) { m_patternsMapCalculated = true; m_patterns = m_globs.patternsMap(); @@ -619,7 +618,7 @@ static void errorMissingMimeTypes( const QStringList& _types ) void KMimeTypeRepository::checkEssentialMimeTypes() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (m_mimeTypesChecked) { // already done return; } @@ -663,7 +662,7 @@ void KMimeTypeRepository::checkEssentialMimeTypes() KMimeType::Ptr KMimeTypeRepository::defaultMimeTypePtr() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (!m_defaultMimeType) { // Try to find the default type KMimeType::Ptr mime = findMimeTypeByName(KMimeType::defaultMimeType()); @@ -684,7 +683,7 @@ bool KMimeTypeRepository::useFavIcons() { // this method will be called quite often, so better not read the config // again and again. - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (!m_useFavIconsChecked) { m_useFavIconsChecked = true; KConfigGroup cg( KGlobal::config(), "HTML Settings" ); @@ -783,7 +782,7 @@ static int mimeDataBaseVersion() int KMimeTypeRepository::sharedMimeInfoVersion() { - QMutexLocker lock(&m_mutex); + std::lock_guard lock(m_mutex); if (m_sharedMimeInfoVersion == 0) m_sharedMimeInfoVersion = mimeDataBaseVersion(); return m_sharedMimeInfoVersion; diff --git a/kdecore/services/kmimetyperepository_p.h b/kdecore/services/kmimetyperepository_p.h index 0f2fdc9e..58a745c0 100644 --- a/kdecore/services/kmimetyperepository_p.h +++ b/kdecore/services/kmimetyperepository_p.h @@ -25,7 +25,7 @@ #include "kmimeglobsfileparser_p.h" #include "kmimetype.h" -#include +#include /** * @internal - this header is not installed @@ -173,7 +173,7 @@ private: QList m_magicRules; KMimeGlobsFileParser::AllGlobs m_globs; KMimeType::Ptr m_defaultMimeType; - QMutex m_mutex; + std::recursive_mutex m_mutex; }; #endif /* KMIMETYPEREPOSITORY_H */ diff --git a/plasma/querymatch.cpp b/plasma/querymatch.cpp index 86788bcf..abd10ee3 100644 --- a/plasma/querymatch.cpp +++ b/plasma/querymatch.cpp @@ -21,14 +21,14 @@ #include #include -#include #include #include #include -#include +#include -#include +#include +#include "kdebug.h" #include "abstractrunner.h" namespace Plasma @@ -39,7 +39,6 @@ class QueryMatchPrivate : public QSharedData public: QueryMatchPrivate(AbstractRunner *r) : QSharedData(), - mutex(new QMutex(QMutex::Recursive)), runner(r), type(QueryMatch::ExactMatch), relevance(.7), @@ -50,10 +49,9 @@ class QueryMatchPrivate : public QSharedData } QueryMatchPrivate(const QueryMatchPrivate &other) - : QSharedData(other), - mutex(new QMutex(QMutex::Recursive)) + : QSharedData(other) { - QMutexLocker lock(other.mutex); + std::lock_guard lock(other.mutex); runner = other.runner; type = other.type; relevance = other.relevance; @@ -69,10 +67,9 @@ class QueryMatchPrivate : public QSharedData ~QueryMatchPrivate() { - delete mutex; } - QMutex *mutex; + mutable std::recursive_mutex mutex; QWeakPointer runner; QueryMatch::Type type; QString id; @@ -142,19 +139,19 @@ AbstractRunner* QueryMatch::runner() const void QueryMatch::setText(const QString &text) { - QMutexLocker locker(d->mutex); + std::lock_guard locker(d->mutex); d->text = text; } void QueryMatch::setSubtext(const QString &subtext) { - QMutexLocker locker(d->mutex); + std::lock_guard locker(d->mutex); d->subtext = subtext; } void QueryMatch::setData(const QVariant & data) { - QMutexLocker locker(d->mutex); + std::lock_guard locker(d->mutex); d->data = data; if (d->id.isEmpty() || d->idSetByData) { @@ -168,7 +165,7 @@ void QueryMatch::setData(const QVariant & data) void QueryMatch::setId(const QString &id) { - QMutexLocker locker(d->mutex); + std::lock_guard locker(d->mutex); if (d->runner) { d->id = d->runner.data()->id(); } @@ -182,7 +179,7 @@ void QueryMatch::setId(const QString &id) void QueryMatch::setIcon(const QIcon &icon) { - QMutexLocker locker(d->mutex); + std::lock_guard locker(d->mutex); d->icon = icon; } diff --git a/threadweaver/Weaver/WeaverImpl.cpp b/threadweaver/Weaver/WeaverImpl.cpp index ab85cf23..846c4d7c 100644 --- a/threadweaver/Weaver/WeaverImpl.cpp +++ b/threadweaver/Weaver/WeaverImpl.cpp @@ -52,12 +52,11 @@ WeaverImpl::WeaverImpl( QObject* parent ) : WeaverInterface(parent) , m_active(0) , m_inventoryMax( qMax(4, 2 * QThread::idealThreadCount() ) ) - , m_mutex ( new QMutex( QMutex::Recursive ) ) , m_finishMutex( new QMutex ) , m_jobAvailableMutex ( new QMutex ) , m_state (0) { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); // initialize state objects: m_states[InConstruction] = new InConstructionState( this ); setState ( InConstruction ); @@ -89,7 +88,7 @@ WeaverImpl::~WeaverImpl() for (;;) { Thread* th = 0; { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); if (m_inventory.isEmpty()) break; th = m_inventory.takeFirst(); } @@ -112,12 +111,11 @@ WeaverImpl::~WeaverImpl() setState ( Destructed ); // m_state = Halted; // FIXME: delete state objects. what sense does DestructedState make then? // FIXME: make state objects static, since they are - delete m_mutex; } void WeaverImpl::setState ( StateId id ) { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); if ( m_state==0 || m_state->stateId() != id ) { m_state = m_states[id]; @@ -135,26 +133,26 @@ void WeaverImpl::setState ( StateId id ) const State& WeaverImpl::state() const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return *m_state; } void WeaverImpl::setMaximumNumberOfThreads( int cap ) { Q_ASSERT_X ( cap > 0, "Weaver Impl", "Thread inventory size has to be larger than zero." ); - QMutexLocker l (m_mutex); + std::lock_guard l(m_mutex); m_inventoryMax = cap; } int WeaverImpl::maximumNumberOfThreads() const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return m_inventoryMax; } int WeaverImpl::currentNumberOfThreads () const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return m_inventory.count (); } @@ -177,7 +175,7 @@ void WeaverImpl::enqueue(Job* job) if (job) { adjustInventory ( 1 ); kDebug() << "queueing job" << job << "of type " << job->metaObject()->className(); - QMutexLocker l (m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); job->aboutToBeQueued ( this ); // find position for insertion:; // FIXME (after 0.6) optimize: factor out queue management into own class, @@ -196,7 +194,7 @@ void WeaverImpl::enqueue(Job* job) void WeaverImpl::adjustInventory ( int numberOfNewJobs ) { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); // no of threads that can be created: const int reserve = m_inventoryMax - m_inventory.count(); @@ -230,7 +228,7 @@ bool WeaverImpl::dequeue ( Job* job ) { bool result; { - QMutexLocker l (m_mutex); + std::lock_guard l(m_mutex); int i = m_assignments.indexOf ( job ); if ( i != -1 ) @@ -255,7 +253,7 @@ bool WeaverImpl::dequeue ( Job* job ) void WeaverImpl::dequeue () { kDebug( "dequeueing all jobs." ); - QMutexLocker l (m_mutex); + std::lock_guard l(m_mutex); for ( int index = 0; index < m_assignments.size(); ++index ) { m_assignments.at( index )->aboutToBeDequeued( this ); @@ -282,7 +280,7 @@ void WeaverImpl::assignJobs() bool WeaverImpl::isEmpty() const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return m_assignments.isEmpty(); } @@ -302,7 +300,7 @@ void WeaverImpl::decActiveThreadCount() void WeaverImpl::adjustActiveThreadCount( int diff ) { - QMutexLocker l (m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); m_active += diff; kDebug() << m_active << "active threads (" << queueLength() << "in queue)."; @@ -315,13 +313,13 @@ void WeaverImpl::adjustActiveThreadCount( int diff ) int WeaverImpl::activeThreadCount() { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return m_active; } Job* WeaverImpl::takeFirstAvailableJob(Job *previous) { - QMutexLocker l (m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); if (previous) { // cleanup and send events: decActiveThreadCount(); @@ -361,13 +359,13 @@ void WeaverImpl::blockThreadUntilJobsAreBeingAssigned ( Thread *th ) int WeaverImpl::queueLength() const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return m_assignments.count(); } bool WeaverImpl::isIdle () const { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); return isEmpty() && m_active == 0; } @@ -392,7 +390,7 @@ void WeaverImpl::finish() void WeaverImpl::requestAbort() { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); for ( int i = 0; irequestAbort(); } @@ -400,7 +398,7 @@ void WeaverImpl::requestAbort() void WeaverImpl::dumpJobs() { - QMutexLocker l(m_mutex); Q_UNUSED(l); + std::lock_guard l(m_mutex); kDebug( "current jobs:" ); for ( int index = 0; index < m_assignments.size(); ++index ) { kDebug() << "-->" diff --git a/threadweaver/Weaver/WeaverImpl.h b/threadweaver/Weaver/WeaverImpl.h index eb825bcf..e32ad25f 100644 --- a/threadweaver/Weaver/WeaverImpl.h +++ b/threadweaver/Weaver/WeaverImpl.h @@ -38,6 +38,8 @@ $Id: WeaverImpl.h 32 2005-08-17 08:38:01Z mirko $ #include "State.h" #include "WeaverInterface.h" +#include + namespace ThreadWeaver { class Job; @@ -165,7 +167,7 @@ namespace ThreadWeaver { private: /** Mutex to serialize operations. */ - QMutex *m_mutex; + mutable std::recursive_mutex m_mutex; /** Non-recursive mutex to serialize calls to finish(). */ QMutex* m_finishMutex; From f7389bcde2ba4afcadaecef185b8fc93c551a029 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 22 Jul 2021 15:36:47 +0300 Subject: [PATCH 6/6] threadweaver: remove redundant QMutex constructor argument Signed-off-by: Ivailo Monev --- threadweaver/Weaver/Job.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threadweaver/Weaver/Job.cpp b/threadweaver/Weaver/Job.cpp index 28442784..ab9bc12a 100644 --- a/threadweaver/Weaver/Job.cpp +++ b/threadweaver/Weaver/Job.cpp @@ -51,7 +51,7 @@ public: Private () : thread (0) , queuePolicies ( new QueuePolicyList ) - , mutex (new QMutex (QMutex::NonRecursive) ) + , mutex (new QMutex () ) , finished (false) {}