Adjust RunnerManager to new ThreadWeaver API using JobPointer
ThreadWeaver does not use Job* anymore which made the code compile fail and some connects being wrong. This patch adjusts RunnerManager to also use QSharedPointer<FindMatchJob> instead of FindMatchJob*. It simplifies a few things as we do no longer have to call e.g. qDeleteAll and fixes the incorrect connects. REVIEW: 111650
This commit is contained in:
parent
39cd64fc68
commit
20b9d17e4c
@ -170,7 +170,7 @@ Plasma::AbstractRunner* FindMatchesJob::runner() const
|
||||
return m_runner;
|
||||
}
|
||||
|
||||
DelayedJobCleaner::DelayedJobCleaner(const QSet<FindMatchesJob *> &jobs, const QSet<AbstractRunner *> &runners)
|
||||
DelayedJobCleaner::DelayedJobCleaner(const QSet<QSharedPointer<FindMatchesJob> > &jobs, const QSet<AbstractRunner *> &runners)
|
||||
: QObject(Weaver::instance()),
|
||||
m_weaver(Weaver::instance()),
|
||||
m_jobs(jobs),
|
||||
@ -178,8 +178,8 @@ DelayedJobCleaner::DelayedJobCleaner(const QSet<FindMatchesJob *> &jobs, const Q
|
||||
{
|
||||
connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished()));
|
||||
|
||||
foreach (FindMatchesJob *job, m_jobs) {
|
||||
connect(job, SIGNAL(done(ThreadWeaver::Job*)), this, SLOT(jobDone(ThreadWeaver::Job*)));
|
||||
for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) {
|
||||
connect((*it).data(), &Job::done, this, &DelayedJobCleaner::jobDone);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,9 +188,9 @@ DelayedJobCleaner::~DelayedJobCleaner()
|
||||
qDeleteAll(m_runners);
|
||||
}
|
||||
|
||||
void DelayedJobCleaner::jobDone(ThreadWeaver::Job *job)
|
||||
void DelayedJobCleaner::jobDone(ThreadWeaver::JobPointer job)
|
||||
{
|
||||
FindMatchesJob *runJob = dynamic_cast<FindMatchesJob *>(job);
|
||||
auto runJob = job.dynamicCast<FindMatchesJob>();
|
||||
|
||||
if (!runJob) {
|
||||
return;
|
||||
@ -207,7 +207,6 @@ void DelayedJobCleaner::jobDone(ThreadWeaver::Job *job)
|
||||
void DelayedJobCleaner::checkIfFinished()
|
||||
{
|
||||
if (m_weaver->isIdle()) {
|
||||
qDeleteAll(m_jobs);
|
||||
m_jobs.clear();
|
||||
deleteLater();
|
||||
}
|
||||
|
@ -127,16 +127,16 @@ private:
|
||||
class DelayedJobCleaner : public QObject
|
||||
{
|
||||
public:
|
||||
DelayedJobCleaner(const QSet<FindMatchesJob*> &jobs, const QSet<AbstractRunner *> &runners = QSet<AbstractRunner *>());
|
||||
DelayedJobCleaner(const QSet<QSharedPointer<FindMatchesJob> > &jobs, const QSet<AbstractRunner *> &runners = QSet<AbstractRunner *>());
|
||||
~DelayedJobCleaner();
|
||||
|
||||
private Q_SLOTS:
|
||||
void jobDone(ThreadWeaver::Job*);
|
||||
void jobDone(ThreadWeaver::JobPointer);
|
||||
void checkIfFinished();
|
||||
|
||||
private:
|
||||
ThreadWeaver::Weaver *m_weaver;
|
||||
QSet<FindMatchesJob*> m_jobs;
|
||||
QSet<QSharedPointer<FindMatchesJob> > m_jobs;
|
||||
QSet<AbstractRunner *> m_runners;
|
||||
};
|
||||
|
||||
|
@ -231,19 +231,27 @@ public:
|
||||
}
|
||||
|
||||
if (!deadRunners.isEmpty()) {
|
||||
QSet<FindMatchesJob *> deadJobs;
|
||||
foreach (FindMatchesJob *job, searchJobs) {
|
||||
QSet<QSharedPointer<FindMatchesJob> > deadJobs;
|
||||
auto it = searchJobs.begin();
|
||||
while (it != searchJobs.end()) {
|
||||
auto &job = (*it);
|
||||
if (deadRunners.contains(job->runner())) {
|
||||
QObject::disconnect(job, SIGNAL(done(ThreadWeaver::Job*)), q, SLOT(jobDone(ThreadWeaver::Job*)));
|
||||
searchJobs.remove(job);
|
||||
QObject::disconnect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer)));
|
||||
it = searchJobs.erase(it);
|
||||
deadJobs.insert(job);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FindMatchesJob *job, oldSearchJobs) {
|
||||
it = oldSearchJobs.begin();
|
||||
while (it != oldSearchJobs.end()) {
|
||||
auto &job = (*it);
|
||||
if (deadRunners.contains(job->runner())) {
|
||||
oldSearchJobs.remove(job);
|
||||
it = oldSearchJobs.erase(it);
|
||||
deadJobs.insert(job);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,9 +317,9 @@ public:
|
||||
return runner;
|
||||
}
|
||||
|
||||
void jobDone(ThreadWeaver::Job *job)
|
||||
void jobDone(ThreadWeaver::JobPointer job)
|
||||
{
|
||||
FindMatchesJob *runJob = dynamic_cast<FindMatchesJob *>(job);
|
||||
auto runJob = job.dynamicCast<FindMatchesJob>();
|
||||
|
||||
if (!runJob) {
|
||||
return;
|
||||
@ -347,9 +355,7 @@ public:
|
||||
}
|
||||
|
||||
if (Weaver::instance()->isIdle()) {
|
||||
qDeleteAll(searchJobs);
|
||||
searchJobs.clear();
|
||||
qDeleteAll(oldSearchJobs);
|
||||
oldSearchJobs.clear();
|
||||
}
|
||||
|
||||
@ -381,7 +387,6 @@ public:
|
||||
{
|
||||
// WORKAROUND: Queue an empty job to force ThreadWeaver to awaken threads
|
||||
if (searchJobs.isEmpty() && Weaver::instance()->isIdle()) {
|
||||
qDeleteAll(oldSearchJobs);
|
||||
oldSearchJobs.clear();
|
||||
checkTearDown();
|
||||
return;
|
||||
@ -408,12 +413,12 @@ public:
|
||||
void startJob(AbstractRunner *runner)
|
||||
{
|
||||
if ((runner->ignoredTypes() & context.type()) == 0) {
|
||||
FindMatchesJob *job = new FindMatchesJob(runner, &context, Weaver::instance());
|
||||
QObject::connect(job, SIGNAL(done(ThreadWeaver::Job*)), q, SLOT(jobDone(ThreadWeaver::Job*)));
|
||||
QSharedPointer<FindMatchesJob> job(new FindMatchesJob(runner, &context, Weaver::instance()));
|
||||
QObject::connect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer)));
|
||||
if (runner->speed() == AbstractRunner::SlowSpeed) {
|
||||
job->setDelayTimer(&delayTimer);
|
||||
}
|
||||
Weaver::instance()->enqueueRaw(job);
|
||||
Weaver::instance()->enqueue(job);
|
||||
searchJobs.insert(job);
|
||||
}
|
||||
}
|
||||
@ -429,8 +434,8 @@ public:
|
||||
QHash<QString, AbstractRunner*> runners;
|
||||
QHash<QString, QString> advertiseSingleRunnerIds;
|
||||
AbstractRunner* currentSingleRunner;
|
||||
QSet<FindMatchesJob*> searchJobs;
|
||||
QSet<FindMatchesJob*> oldSearchJobs;
|
||||
QSet<QSharedPointer<FindMatchesJob> > searchJobs;
|
||||
QSet<QSharedPointer<FindMatchesJob> > oldSearchJobs;
|
||||
KConfigGroup conf;
|
||||
QString singleModeRunnerId;
|
||||
bool loadAll : 1;
|
||||
@ -615,8 +620,8 @@ void RunnerManager::run(const QueryMatch &match)
|
||||
//TODO: this function is not const as it may be used for learning
|
||||
AbstractRunner *runner = match.runner();
|
||||
|
||||
foreach (FindMatchesJob *job, d->searchJobs) {
|
||||
if (job->runner() == runner && !job->isFinished()) {
|
||||
for (auto it = d->searchJobs.constBegin(); it != d->searchJobs.constEnd(); ++it) {
|
||||
if ((*it)->runner() == runner && !(*it)->isFinished()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "deferred run";
|
||||
#endif
|
||||
@ -775,12 +780,10 @@ void RunnerManager::reset()
|
||||
{
|
||||
// If ThreadWeaver is idle, it is safe to clear previous jobs
|
||||
if (Weaver::instance()->isIdle()) {
|
||||
qDeleteAll(d->searchJobs);
|
||||
qDeleteAll(d->oldSearchJobs);
|
||||
d->oldSearchJobs.clear();
|
||||
} else {
|
||||
Q_FOREACH(FindMatchesJob *job, d->searchJobs) {
|
||||
Weaver::instance()->dequeueRaw(job);
|
||||
for (auto it = d->searchJobs.constBegin(); it != d->searchJobs.constEnd(); ++it) {
|
||||
Weaver::instance()->dequeue((*it));
|
||||
}
|
||||
d->oldSearchJobs += d->searchJobs;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void scheduleMatchesChanged())
|
||||
Q_PRIVATE_SLOT(d, void matchesChanged())
|
||||
Q_PRIVATE_SLOT(d, void jobDone(ThreadWeaver::Job*))
|
||||
Q_PRIVATE_SLOT(d, void jobDone(ThreadWeaver::JobPointer))
|
||||
Q_PRIVATE_SLOT(d, void unblockJobs())
|
||||
Q_PRIVATE_SLOT(d, void runnerMatchingSuspended(bool))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user