plasma: unlock Plasma::QueryMatch

assuming that match (Plasma::QueryMatch) objects are modified by one thread
in the runner itself only or operated on a copy of one matching does not
need a mutex

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-18 07:43:34 +03:00
parent 5f23665baa
commit afb548b2ed
3 changed files with 8 additions and 21 deletions

View file

@ -100,7 +100,7 @@ void AbstractRunner::performMatch(Plasma::RunnerContext &localContext)
QElapsedTimer time; QElapsedTimer time;
time.restart(); time.restart();
//The local copy is already obtained in the job // The local copy is already obtained in the job
match(localContext); match(localContext);
// automatically rate limit runners that become slooow // automatically rate limit runners that become slooow
@ -168,10 +168,10 @@ void AbstractRunner::clearActions()
d->actions.clear(); d->actions.clear();
} }
QMimeData * AbstractRunner::mimeDataForMatch(const QueryMatch *match) QMimeData* AbstractRunner::mimeDataForMatch(const QueryMatch *match)
{ {
Q_UNUSED(match) Q_UNUSED(match)
return 0; return nullptr;
} }
AbstractRunner::Speed AbstractRunner::speed() const AbstractRunner::Speed AbstractRunner::speed() const
@ -253,10 +253,10 @@ void AbstractRunner::init()
AbstractRunnerPrivate::AbstractRunnerPrivate(AbstractRunner *r) AbstractRunnerPrivate::AbstractRunnerPrivate(AbstractRunner *r)
: priority(AbstractRunner::NormalPriority), : priority(AbstractRunner::NormalPriority),
speed(AbstractRunner::NormalSpeed), speed(AbstractRunner::NormalSpeed),
blackListed(0), blackListed(0),
runner(r), runner(r),
fastRuns(0) fastRuns(0)
{ {
} }

View file

@ -19,7 +19,6 @@
#include "runnerjobs_p.h" #include "runnerjobs_p.h"
#include "runnermanager.h" #include "runnermanager.h"
#include "plasma/querymatch.h"
#include "kdebug.h" #include "kdebug.h"
namespace Plasma { namespace Plasma {

View file

@ -26,8 +26,6 @@
#include <QVariant> #include <QVariant>
#include <QSharedPointer> #include <QSharedPointer>
#include <mutex>
#include "kdebug.h" #include "kdebug.h"
#include "abstractrunner.h" #include "abstractrunner.h"
@ -50,7 +48,6 @@ class QueryMatchPrivate : public QSharedData
QueryMatchPrivate(const QueryMatchPrivate &other) QueryMatchPrivate(const QueryMatchPrivate &other)
: QSharedData(other) : QSharedData(other)
{ {
std::lock_guard<std::recursive_mutex> lock(other.mutex);
runner = other.runner; runner = other.runner;
relevance = other.relevance; relevance = other.relevance;
selAction = other.selAction; selAction = other.selAction;
@ -63,7 +60,6 @@ class QueryMatchPrivate : public QSharedData
data = other.data; data = other.data;
} }
mutable std::recursive_mutex mutex;
QWeakPointer<AbstractRunner> runner; QWeakPointer<AbstractRunner> runner;
QString id; QString id;
QString text; QString text;
@ -121,21 +117,17 @@ AbstractRunner* QueryMatch::runner() const
void QueryMatch::setText(const QString &text) void QueryMatch::setText(const QString &text)
{ {
std::lock_guard<std::recursive_mutex> locker(d->mutex);
d->text = text; d->text = text;
} }
void QueryMatch::setSubtext(const QString &subtext) void QueryMatch::setSubtext(const QString &subtext)
{ {
std::lock_guard<std::recursive_mutex> locker(d->mutex);
d->subtext = subtext; d->subtext = subtext;
} }
void QueryMatch::setData(const QVariant & data) void QueryMatch::setData(const QVariant & data)
{ {
std::lock_guard<std::recursive_mutex> locker(d->mutex);
d->data = data; d->data = data;
if (d->id.isEmpty() || d->idSetByData) { if (d->id.isEmpty() || d->idSetByData) {
const QString id = data.toString(); const QString id = data.toString();
if (!id.isEmpty()) { if (!id.isEmpty()) {
@ -147,21 +139,17 @@ void QueryMatch::setData(const QVariant & data)
void QueryMatch::setId(const QString &id) void QueryMatch::setId(const QString &id)
{ {
std::lock_guard<std::recursive_mutex> locker(d->mutex);
if (d->runner) { if (d->runner) {
d->id = d->runner.data()->id(); d->id = d->runner.data()->id();
} }
if (!id.isEmpty()) { if (!id.isEmpty()) {
d->id.append('_').append(id); d->id.append('_').append(id);
} }
d->idSetByData = false; d->idSetByData = false;
} }
void QueryMatch::setIcon(const QIcon &icon) void QueryMatch::setIcon(const QIcon &icon)
{ {
std::lock_guard<std::recursive_mutex> locker(d->mutex);
d->icon = icon; d->icon = icon;
} }
@ -240,7 +228,7 @@ bool QueryMatch::operator!=(const QueryMatch &other) const
void QueryMatch::run() const void QueryMatch::run() const
{ {
//kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype(); // kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype();
if (d->runner) { if (d->runner) {
d->runner.data()->run(*this); d->runner.data()->run(*this);
} }