"...and they lived happily ever after with no more duplicate matches =)"

A local copy of the context is now created in the FindMatchesJob ctor, not anymore in AbstractRunner, this prevents old queries to be run with a valid dptr 

svn path=/trunk/KDE/kdelibs/; revision=935342
This commit is contained in:
Jacopo De Simoi 2009-03-04 21:03:33 +00:00
parent 5332b1edc8
commit 8aa4045953
4 changed files with 9 additions and 8 deletions

View File

@ -132,14 +132,14 @@ void AbstractRunner::reloadConfiguration()
{ {
} }
void AbstractRunner::performMatch(Plasma::RunnerContext &globalContext) void AbstractRunner::performMatch(Plasma::RunnerContext &localContext)
{ {
static const int reasonableRunTime = 1500; static const int reasonableRunTime = 1500;
static const int fastEnoughTime = 250; static const int fastEnoughTime = 250;
d->runtime.restart(); d->runtime.restart();
//TODO :this is a copy ctor
RunnerContext localContext(globalContext, 0); //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
const int runtime = d->runtime.elapsed(); const int runtime = d->runtime.elapsed();

View File

@ -125,7 +125,7 @@ void DefaultRunnerPolicy::destructed(Job *job)
FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner,
Plasma::RunnerContext *context, QObject *parent) Plasma::RunnerContext *context, QObject *parent)
: ThreadWeaver::Job(parent), : ThreadWeaver::Job(parent),
m_context(context), m_context(*context, 0),
m_runner(runner), m_runner(runner),
m_timer(0), m_timer(0),
m_stale(false) m_stale(false)
@ -155,7 +155,7 @@ void FindMatchesJob::run()
{ {
// kDebug() << "Running match for " << m_runner->objectName() // kDebug() << "Running match for " << m_runner->objectName()
// << " in Thread " << thread()->id() << endl; // << " in Thread " << thread()->id() << endl;
m_runner->performMatch(*m_context); m_runner->performMatch(m_context);
} }
int FindMatchesJob::priority() const int FindMatchesJob::priority() const

View File

@ -118,7 +118,7 @@ protected:
void run(); void run();
private: private:
Plasma::RunnerContext *m_context; Plasma::RunnerContext m_context;
Plasma::AbstractRunner *m_runner; Plasma::AbstractRunner *m_runner;
QTimer *m_timer; QTimer *m_timer;
bool m_stale; bool m_stale;

View File

@ -390,8 +390,9 @@ bool RunnerManager::execQuery(const QString &term, const QString &runnerName)
//kDebug() << "ignored!"; //kDebug() << "ignored!";
return false; return false;
} }
//CHECK: the match is performed in the same thread, do we really need a local copy?
r->performMatch(d->context); RunnerContext localContext(d->context, 0);
r->performMatch(localContext);
//kDebug() << "succeeded with" << d->context.matches().count() << "results"; //kDebug() << "succeeded with" << d->context.matches().count() << "results";
emit matchesChanged(d->context.matches()); emit matchesChanged(d->context.matches());
return true; return true;