Commit e062ada0 authored by Dario Freddi's avatar Dario Freddi

Make validator and runner a QRunnable instead of a QThread. This relieves...

Make validator and runner a QRunnable instead of a QThread. This relieves thread dispatching around, making everything slightly faster and more reliable. The only downside is that we have to force maxThreadCount to be >=2, since in some cases we're using QtConcurrent straight from a different thread.
Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent ea11d99b
......@@ -274,6 +274,12 @@ Backend::Backend(QObject* parent)
qRegisterMetaType<QUuid>();
qRegisterMetaType< QList< Akabei::Package* > >();
qRegisterMetaType< QList< Akabei::Group* > >();
// We need at least 2 threads in QThreadPool to make everything work correctly.
if (QThreadPool::globalInstance()->maxThreadCount() < 2) {
qDebug() << "Set max thread count to 2";
QThreadPool::globalInstance()->setMaxThreadCount(2);
}
}
Backend::~Backend()
......
......@@ -12,6 +12,7 @@
#include "akabeivalidatorthread_p.h"
#include "akabeirunnerthread_p.h"
#include "akabeioperation_p.h"
#include <QtCore/qthreadpool.h>
namespace Akabei
{
......@@ -154,10 +155,8 @@ void OperationRunner::validate()
this, SLOT(__k__errorsOccurred(ErrorList)));
connect(d->valThread.data(), SIGNAL(validationFinished(bool,OpsHash)),
this, SLOT(__k__validationFinished(bool,OpsHash)));
connect(d->valThread.data(), SIGNAL(finished()),
d->valThread.data(), SLOT(deleteLater()));
d->valThread.data()->start();
QThreadPool::globalInstance()->start(d->valThread.data());
}
void OperationRunner::run()
......@@ -181,7 +180,7 @@ void OperationRunner::run()
connect(d->runThread.data(), SIGNAL(runFinished(bool)),
this, SIGNAL(finished(bool)));
d->runThread.data()->start();
QThreadPool::globalInstance()->start(d->runThread.data());
}
void OperationRunner::cancel()
......
......@@ -22,7 +22,8 @@ namespace Akabei
{
RunnerThread::RunnerThread(const QHash<Operation::Phase, QList< Operation* > > &ops, QObject* parent)
: QThread(parent)
: QObject(parent)
, QRunnable()
, m_operations(ops)
{
......@@ -151,6 +152,7 @@ QList< Error* > RunnerThread::runConcurrent(const QList< Operation* >& ops)
QFuture< void > future = QtConcurrent::map(ops, RunnerThread::runSingle);
s_runFutureWatcher.data()->setFuture(future);
e.exec();
if (s_runFutureWatcher.data()->isCanceled()) {
// Manage errors...
QList< Error* > errors;
......
......@@ -14,13 +14,14 @@
#include <QtCore/QThread>
#include <QtCore/QHash>
#include <QtCore/QWeakPointer>
#include <QtCore/QRunnable>
#include "akabeioperation.h"
#include "akabeioperationrunner_p.h"
namespace Akabei {
class RunnerThread : public QThread
class RunnerThread : public QObject, public QRunnable
{
Q_OBJECT
public:
......
......@@ -39,7 +39,8 @@ QString queryFromName(const QString &name)
}
ValidatorThread::ValidatorThread(const QHash<Operation::Phase, QList< Operation* > > &ops, QObject* parent)
: QThread(parent)
: QObject(parent)
, QRunnable()
, m_operations(ops)
{
}
......
......@@ -14,9 +14,8 @@
#include "akabeioperation.h"
#include "akabeioperationrunner_p.h"
#include <QtCore/QThread>
#include <QtCore/QRunnable>
#include <QtCore/QHash>
#include <QtCore/QMetaType>
namespace Akabei {
class Error;
......@@ -29,7 +28,7 @@ class OperationPrivate;
this decides if your system will be fucked up by a wrong transaction or be spared.
Be careful.
*/
class ValidatorThread : public QThread
class ValidatorThread : public QObject, public QRunnable
{
Q_OBJECT
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment