Message info
 
To:kde-commits@kde.org From:Benjamin Girault Subject:[kipi-plugins] common/libkipiplugins/tools/threads: KPActionThread bugfixes Date:Sun, 18 Mar 2012 17:36:14 +0100 (CET)
 

Git commit 456b3c58db738a1451304fd1c4fe19577477614d by Benjamin Girault.
Committed on 15/03/2012 at 22:14.
Pushed by girault into branch 'master'.

KPActionThread bugfixes

M +15 -16 common/libkipiplugins/tools/threads/kpactionthreadbase.cpp
M +1 -0 common/libkipiplugins/tools/threads/kpactionthreadbase.h

http://commits.kde.org/kipi-plugins/456b3c58db738a1451304fd1c4fe19577477614d

diff --git a/common/libkipiplugins/tools/threads/kpactionthreadbase.cpp b/common/libkipiplugins/tools/threads/kpactionthreadbase.cpp
index d4650be..d660ccd 100644
--- a/common/libkipiplugins/tools/threads/kpactionthreadbase.cpp
+++ b/common/libkipiplugins/tools/threads/kpactionthreadbase.cpp
@@ -38,6 +38,7 @@
#include <ThreadWeaver/Weaver>
#include <threadweaver/ThreadWeaver.h>
#include <threadweaver/Job.h>
+#include <threadweaver/DebuggingAids.h>
#include <solid/device.h>

using namespace Solid;
@@ -57,11 +58,10 @@ public:
log = 0;
}

- bool running;
- bool weaverRunning;
+ volatile bool running;
+ volatile bool weaverRunning;

QWaitCondition condVarJobs;
- QWaitCondition condVar;
QMutex mutex;
QList<JobCollection*> todo;

@@ -89,6 +89,7 @@ KPActionThreadBase::~KPActionThreadBase()
wait();

delete d->log;
+ delete d->weaver;
delete d;
}

@@ -106,16 +107,21 @@ void KPActionThreadBase::cancel()
d->todo.clear();
d->running = false;
d->weaverRunning = true;
+ d->weaver->requestAbort();
d->weaver->dequeue();
- d->condVar.wakeAll();
d->condVarJobs.wakeAll();
}

+void KPActionThreadBase::finish()
+{
+ d->weaver->finish();
+}
+
void KPActionThreadBase::appendJob(JobCollection* const job)
{
QMutexLocker lock(&d->mutex);
d->todo << job;
- d->condVar.wakeAll();
+ d->condVarJobs.wakeAll();
}

void KPActionThreadBase::run()
@@ -129,20 +135,13 @@ void KPActionThreadBase::run()
JobCollection* t = 0;
{
QMutexLocker lock(&d->mutex);
- if (!d->todo.isEmpty())
+ if (!d->todo.isEmpty() && !d->weaverRunning)
{
- if (!d->weaverRunning)
- {
- t = d->todo.takeFirst();
- }
- else
- {
- d->condVarJobs.wait(&d->mutex);
- }
+ t = d->todo.takeFirst();
}
else
{
- d->condVar.wait(&d->mutex);
+ d->condVarJobs.wait(&d->mutex);
}
}

@@ -154,8 +153,8 @@ void KPActionThreadBase::run()
connect(t, SIGNAL(done(ThreadWeaver::Job*)),
t, SLOT(deleteLater()));

- d->weaver->enqueue(t);
d->weaverRunning = true;
+ d->weaver->enqueue(t);
}
}

diff --git a/common/libkipiplugins/tools/threads/kpactionthreadbase.h b/common/libkipiplugins/tools/threads/kpactionthreadbase.h
index f4af317..fc70d7f 100644
--- a/common/libkipiplugins/tools/threads/kpactionthreadbase.h
+++ b/common/libkipiplugins/tools/threads/kpactionthreadbase.h
@@ -53,6 +53,7 @@ public:
~KPActionThreadBase();

void cancel();
+ void finish();

protected: