Commit 751a0d3a authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa
Browse files

Do not connect to KJob::result() from the worker thread.

This is another step towards getting rid of the threading mess we
currently have.

We previously connected to KJob::result() from the worker thread using
Qt::DirectConnection just to make sure QThread::quit() was called
right away (synchronously). We now make the connection from the main
thread without Qt::DirectConnection, and just make sure we start the
worker thread's event loop if there is an actual need to.

The other use of Qt::DirectConnection in the worker thread (via
QMetaObject::invkeMethod) has also been removed, as it was there to
make sure the method was called right away from the worker thread as
well.

svn path=/trunk/KDE/kdeutils/ark/; revision=1240914
parent bcad03cd
......@@ -42,17 +42,26 @@ namespace Kerfuffle
class Job::Private : public QThread
{
public:
Private(Job *job, QObject *parent = 0)
: QThread(parent)
, q(job)
{
connect(q, SIGNAL(result(KJob*)), SLOT(quit()));
}
virtual void run();
private:
Job *q;
};
void Job::Private::run()
{
connect(q, SIGNAL(result(KJob*)), this, SLOT(quit()), Qt::DirectConnection);
q->doWork();
QMetaObject::invokeMethod(q, "doWork", Qt::DirectConnection);
exec();
if (q->isRunning()) {
exec();
}
#ifdef DEBUG_RACECONDITION
QThread::sleep(2);
......@@ -62,10 +71,9 @@ void Job::Private::run()
Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
: KJob(parent)
, m_interface(interface)
, d(new Private())
, m_isRunning(false)
, d(new Private(this))
{
d->q = this;
static bool onlyOnce = false;
if (!onlyOnce) {
qRegisterMetaType<QPair<QString, QString> >("QPair<QString,QString>");
......@@ -84,11 +92,23 @@ Job::~Job()
delete d;
}
bool Job::isRunning() const
{
return m_isRunning;
}
void Job::start()
{
m_isRunning = true;
d->start();
}
void Job::emitResult()
{
m_isRunning = false;
KJob::emitResult();
}
void Job::onError(const QString & message, const QString & details)
{
Q_UNUSED(details)
......
......@@ -60,10 +60,13 @@ public:
virtual void onFinished(bool result);
virtual void onUserQuery(class Query *query);
bool isRunning() const;
protected:
Job(ReadOnlyArchiveInterface *interface, QObject *parent = 0);
virtual ~Job();
virtual bool doKill();
virtual void emitResult();
ReadOnlyArchiveInterface *m_interface;
......@@ -77,6 +80,8 @@ signals:
void userQuery(Kerfuffle::Query*);
private:
bool m_isRunning;
class Private;
Private * const d;
};
......
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