make sure that we don't get hung up with old jobs that aren't enqueued anymore by checking for that case more often

svn path=/trunk/KDE/kdelibs/; revision=1053930
This commit is contained in:
Aaron J. Seigo 2009-11-25 01:54:44 +00:00
parent 65eda15e5d
commit c43ef1bcb8
2 changed files with 18 additions and 3 deletions

View File

@ -21,7 +21,7 @@
#include <QTimer>
//#include <KDebug>
#include <kdebug.h>
//#include <Weaver/DebuggingAids.h>
#include <Weaver/ThreadWeaver.h>
@ -52,6 +52,7 @@ bool DelayedRunnerPolicy::canRun(Job *job)
FindMatchesJob *aJob = static_cast<FindMatchesJob*>(job);
if (QTimer *t = aJob->delayTimer()) {
// If the timer is active, the required delay has not been reached
//kDebug() << "delayed timer" << aJob->runner()->name() << !t->isActive();
return !t->isActive();
}

View File

@ -34,10 +34,11 @@
#include <solid/deviceinterface.h>
#include <Weaver/DebuggingAids.h>
#include <Weaver/State.h>
#include <Weaver/Thread.h>
#include <Weaver/ThreadWeaver.h>
#include "private/runnerjobs.h"
#include "private/runnerjobs_p.h"
#include "querymatch.h"
using ThreadWeaver::Weaver;
@ -225,6 +226,13 @@ public:
return;
}
if (Weaver::instance()->isIdle()) {
qDeleteAll(searchJobs);
searchJobs.clear();
qDeleteAll(oldSearchJobs);
oldSearchJobs.clear();
}
if (searchJobs.isEmpty() && oldSearchJobs.isEmpty()) {
foreach (AbstractRunner *runner, runners) {
emit runner->teardown();
@ -238,7 +246,13 @@ public:
void unblockJobs()
{
// WORKAROUND: Queue an empty job to force ThreadWeaver to awaken threads
// kDebug() << "- Unblocking jobs -" << endl;
if (searchJobs.isEmpty() && Weaver::instance()->isIdle()) {
qDeleteAll(oldSearchJobs);
oldSearchJobs.clear();
checkTearDown();
return;
}
DummyJob *dummy = new DummyJob(q);
Weaver::instance()->enqueue(dummy);
QObject::connect(dummy, SIGNAL(done(ThreadWeaver::Job*)), dummy, SLOT(deleteLater()));