1/*
2 SPDX-FileCopyrightText: 2022 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "kiocoredebug.h"
8#include "slavebase.h"
9#include "workerbase.h"
10#include "workerbase_p.h"
11#include "workerfactory.h"
12#include "workerthread_p.h"
13
14namespace KIO
15{
16
17WorkerThread::WorkerThread(QObject *parent, WorkerFactory *factory, const QByteArray &appSocket)
18 : QThread(parent)
19 , m_factory(factory)
20 , m_appSocket(appSocket)
21{
22}
23
24WorkerThread::~WorkerThread()
25{
26 wait();
27}
28
29void WorkerThread::abort()
30{
31 QMutexLocker locker(&m_workerMutex);
32 if (m_worker) { // not deleted yet
33 m_worker->exit();
34 }
35}
36
37void WorkerThread::run()
38{
39 qCDebug(KIO_CORE) << QThread::currentThreadId() << "Creating threaded worker";
40
41 auto worker = m_factory->createWorker(pool: {}, app: m_appSocket);
42 SlaveBase *base = &(worker->d->bridge);
43
44 base->setRunInThread(true);
45 setWorker(base);
46
47 base->dispatchLoop();
48
49 setWorker(nullptr); // before the actual deletion
50}
51
52void WorkerThread::setWorker(SlaveBase *worker)
53{
54 QMutexLocker locker(&m_workerMutex);
55 m_worker = worker;
56}
57
58} // namespace KIO
59
60#include "moc_workerthread_p.cpp"
61

source code of kio/src/core/workerthread.cpp