if the RunnerManager is deleted but jobs are still processing, create a helper object to wait it out and clean them up when possible

svn path=/trunk/KDE/kdelibs/; revision=938728
This commit is contained in:
Aaron J. Seigo 2009-03-12 20:25:52 +00:00
parent 02f16ea848
commit 3ecfa9f6d5
3 changed files with 55 additions and 1 deletions

View File

@ -167,6 +167,24 @@ Plasma::AbstractRunner* FindMatchesJob::runner() const
return m_runner;
}
DelayedJobCleaner::DelayedJobCleaner(QSet<FindMatchesJob*> jobs, ThreadWeaver::WeaverInterface *weaver)
: QObject(weaver),
m_weaver(weaver),
m_jobs(jobs)
{
connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished()));
}
void DelayedJobCleaner::checkIfFinished()
{
if (m_weaver->isIdle()) {
qDeleteAll(m_jobs);
m_jobs.clear();
deleteLater();
}
}
} // Plasma namespace
// #include "runnerjobs.moc"

View File

@ -22,6 +22,7 @@
#include <QHash>
#include <QMutex>
#include <QSet>
#include <Weaver/Job.h>
#include <Weaver/QueuePolicy.h>
@ -120,6 +121,21 @@ private:
QTimer *m_timer;
};
class DelayedJobCleaner : public QObject
{
public:
DelayedJobCleaner(QSet<FindMatchesJob*> jobs, ThreadWeaver::WeaverInterface *weaver);
private Q_SLOTS:
void jobDone(ThreadWeaver::Job*);
void checkIfFinished();
//connect(ThreadWeaver::instance(), SIGNAL(finished()), this, SLOT(checkIfFinished()));
private:
ThreadWeaver::WeaverInterface *m_weaver;
QSet<FindMatchesJob*> m_jobs;
};
}
#endif

View File

@ -160,7 +160,12 @@ public:
void jobDone(ThreadWeaver::Job *job)
{
FindMatchesJob *runJob = static_cast<FindMatchesJob*>(job);
FindMatchesJob *runJob = dynamic_cast<FindMatchesJob*>(job);
if (!runJob) {
return;
}
if (deferredRun.isEnabled() && runJob->runner() == deferredRun.runner()) {
//kDebug() << "job actually done, running now **************";
QueryMatch tmpRun = deferredRun;
@ -189,6 +194,17 @@ public:
QObject::connect(dummy, SIGNAL(done(ThreadWeaver::Job*)), dummy, SLOT(deleteLater()));
}
void checkIfFinished()
{
if (Weaver::instance()->isIdle()) {
qDeleteAll(searchJobs);
searchJobs.clear();
qDeleteAll(oldSearchJobs);
oldSearchJobs.clear();
q->deleteLater();
}
}
// Delay in ms before slow runners are allowed to run
static const int slowRunDelay = 400;
@ -230,6 +246,10 @@ RunnerManager::RunnerManager(KConfigGroup &c, QObject *parent)
RunnerManager::~RunnerManager()
{
if (!qApp->closingDown && (!d->searchJobs.isEmpty() || !d->oldSearchJobs.isEmpty())) {
new DelayedJobCleaner(d->searchJobs + d->oldSearchJobs, Weaver::instance());
}
delete d;
}