when setAllowedRunners is called, call loadRunners, which now also allows for being called while a search is in progress

loadRunners intelligently only unloads those runners with are no longer to be loaded, so this is a performance win.
it now also checks to see if there are pending jobs for the runners to be deleted (if any) and if so it creates a delayed
deleter for them -> no crashes
This commit is contained in:
Aaron Seigo 2011-11-22 12:17:06 +01:00
parent 7f0e9fb3b2
commit f6f8d8b2ee
3 changed files with 45 additions and 12 deletions

View File

@ -170,10 +170,11 @@ Plasma::AbstractRunner* FindMatchesJob::runner() const
return m_runner; return m_runner;
} }
DelayedJobCleaner::DelayedJobCleaner(QSet<FindMatchesJob*> jobs, ThreadWeaver::WeaverInterface *weaver) DelayedJobCleaner::DelayedJobCleaner(const QSet<FindMatchesJob *> &jobs, const QSet<AbstractRunner *> &runners)
: QObject(weaver), : QObject(Weaver::instance()),
m_weaver(weaver), m_weaver(Weaver::instance()),
m_jobs(jobs) m_jobs(jobs),
m_runners(runners)
{ {
connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished()));
@ -182,6 +183,11 @@ DelayedJobCleaner::DelayedJobCleaner(QSet<FindMatchesJob*> jobs, ThreadWeaver::W
} }
} }
DelayedJobCleaner::~DelayedJobCleaner()
{
qDeleteAll(m_runners);
}
void DelayedJobCleaner::jobDone(ThreadWeaver::Job *job) void DelayedJobCleaner::jobDone(ThreadWeaver::Job *job)
{ {
FindMatchesJob *runJob = dynamic_cast<FindMatchesJob *>(job); FindMatchesJob *runJob = dynamic_cast<FindMatchesJob *>(job);

View File

@ -126,16 +126,17 @@ private:
class DelayedJobCleaner : public QObject class DelayedJobCleaner : public QObject
{ {
public: public:
DelayedJobCleaner(QSet<FindMatchesJob*> jobs, ThreadWeaver::WeaverInterface *weaver); DelayedJobCleaner(const QSet<FindMatchesJob*> &jobs, const QSet<AbstractRunner *> &runners = QSet<AbstractRunner *>());
~DelayedJobCleaner();
private Q_SLOTS: private Q_SLOTS:
void jobDone(ThreadWeaver::Job*); void jobDone(ThreadWeaver::Job*);
void checkIfFinished(); void checkIfFinished();
//connect(ThreadWeaver::instance(), SIGNAL(finished()), this, SLOT(checkIfFinished()));
private: private:
ThreadWeaver::WeaverInterface *m_weaver; ThreadWeaver::WeaverInterface *m_weaver;
QSet<FindMatchesJob*> m_jobs; QSet<FindMatchesJob*> m_jobs;
QSet<AbstractRunner *> m_runners;
}; };
} }

View File

@ -188,6 +188,7 @@ public:
advertiseSingleRunnerIds.clear(); advertiseSingleRunnerIds.clear();
QSet<AbstractRunner *> deadRunners;
QMutableListIterator<KPluginInfo> it(offers); QMutableListIterator<KPluginInfo> it(offers);
while (it.hasNext()) { while (it.hasNext()) {
KPluginInfo &description = it.next(); KPluginInfo &description = it.next();
@ -223,9 +224,32 @@ public:
} }
} else if (loaded) { } else if (loaded) {
//Remove runner //Remove runner
AbstractRunner *runner = runners.take(runnerName); deadRunners.insert(runners.take(runnerName));
kDebug() << "Removing runner: " << runnerName; kDebug() << "Removing runner: " << runnerName;
delete runner; }
}
if (!deadRunners.isEmpty()) {
QSet<FindMatchesJob *> deadJobs;
foreach (FindMatchesJob *job, searchJobs) {
if (deadRunners.contains(job->runner())) {
QObject::disconnect(job, SIGNAL(done(ThreadWeaver::Job*)), q, SLOT(jobDone(ThreadWeaver::Job*)));
searchJobs.remove(job);
deadJobs.insert(job);
}
}
foreach (FindMatchesJob *job, oldSearchJobs) {
if (deadRunners.contains(job->runner())) {
oldSearchJobs.remove(job);
deadJobs.insert(job);
}
}
if (deadJobs.isEmpty()) {
qDeleteAll(deadRunners);
} else {
new DelayedJobCleaner(deadJobs, deadRunners);
} }
} }
@ -429,7 +453,7 @@ RunnerManager::RunnerManager(KConfigGroup &c, QObject *parent)
RunnerManager::~RunnerManager() RunnerManager::~RunnerManager()
{ {
if (!qApp->closingDown() && (!d->searchJobs.isEmpty() || !d->oldSearchJobs.isEmpty())) { if (!qApp->closingDown() && (!d->searchJobs.isEmpty() || !d->oldSearchJobs.isEmpty())) {
new DelayedJobCleaner(d->searchJobs + d->oldSearchJobs, Weaver::instance()); new DelayedJobCleaner(d->searchJobs + d->oldSearchJobs);
} }
delete d; delete d;
@ -443,11 +467,13 @@ void RunnerManager::reloadConfiguration()
void RunnerManager::setAllowedRunners(const QStringList &runners) void RunnerManager::setAllowedRunners(const QStringList &runners)
{ {
qDeleteAll(d->runners);
d->runners.clear();
KConfigGroup config = d->configGroup(); KConfigGroup config = d->configGroup();
config.writeEntry("pluginWhiteList", runners); config.writeEntry("pluginWhiteList", runners);
if (!d->runners.isEmpty()) {
// this has been called with runners already created. so let's do an instant reload
d->loadRunners();
}
} }
QStringList RunnerManager::allowedRunners() const QStringList RunnerManager::allowedRunners() const