diff options
author | Gerry Boland <gerry.boland@canonical.com> | 2015-05-18 13:30:33 -0500 |
---|---|---|
committer | Gerry Boland <gerry.boland@canonical.com> | 2015-05-18 13:30:33 -0500 |
commit | cc5eeb7da8e74965f87e7969d4db3f04e6bd21f3 (patch) | |
tree | b5094d77c47f71139ec5b920559e5111b220276c /src | |
parent | 12f0061f828610e827a4f0549535517483c13e3f (diff) |
Fix shutdown issues by inheriting QThread directly - also get to avoid having qt event loop for mir
Diffstat (limited to 'src')
-rw-r--r-- | src/platforms/mirserver/qmirserver.cpp | 27 | ||||
-rw-r--r-- | src/platforms/mirserver/qmirserver_p.cpp | 10 | ||||
-rw-r--r-- | src/platforms/mirserver/qmirserver_p.h | 12 |
3 files changed, 20 insertions, 29 deletions
diff --git a/src/platforms/mirserver/qmirserver.cpp b/src/platforms/mirserver/qmirserver.cpp index acf3bb9..61ea1ba 100644 --- a/src/platforms/mirserver/qmirserver.cpp +++ b/src/platforms/mirserver/qmirserver.cpp @@ -43,12 +43,9 @@ QMirServer::QMirServer(const QStringList &arguments, QObject *parent) d->server = QSharedPointer<MirServer>(new MirServer(argc, const_cast<const char**>(argv))); - d->serverWorker = new MirServerWorker(d->server); - d->serverWorker->moveToThread(&d->serverThread); + d->serverThread = new MirServerThread(d->server); -/* connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, - d->serverWorker, &MirServerWorker::stop, Qt::DirectConnection);*/ // see FIXME in MirServerWorker - connect(d->serverWorker, &MirServerWorker::stopped, this, &QMirServer::serverStopped, Qt::DirectConnection); + connect(d->serverThread, &MirServerThread::stopped, this, &QMirServer::serverStopped); } QMirServer::~QMirServer() @@ -60,10 +57,9 @@ bool QMirServer::start() { Q_D(QMirServer); - d->serverThread.start(QThread::TimeCriticalPriority); - QMetaObject::invokeMethod(d->serverWorker, "run"); + d->serverThread->start(QThread::TimeCriticalPriority); - if (!d->serverWorker->waitForMirStartup()) + if (!d->serverThread->waitForMirStartup()) { qCritical() << "ERROR: QMirServer - Mir failed to start"; return false; @@ -77,13 +73,12 @@ bool QMirServer::stop() { Q_D(QMirServer); - if (d->serverThread.isRunning()) { - d->serverWorker->stop(); - //QMetaObject::invokeMethod(d->serverWorker, "stop"); - if (!d->serverThread.wait(10000)) { + if (d->serverThread->isRunning()) { + d->serverThread->stop(); + if (!d->serverThread->wait(10000)) { // do something to indicate fail during shutdown qCritical() << "ERROR: QMirServer - Mir failed to shut down correctly, terminating it"; - d->serverThread.terminate(); + d->serverThread->terminate(); return false; } } @@ -93,15 +88,15 @@ bool QMirServer::stop() bool QMirServer::isRunning() const { Q_D(const QMirServer); - return d->serverThread.isRunning(); + return d->serverThread->isRunning(); } void QMirServer::serverStopped() { Q_D(QMirServer); - if (d->serverThread.isRunning()) - d->serverThread.quit(); + if (d->serverThread->isRunning()) + d->serverThread->quit(); // if unexpected mir server stop, better quit the QApplication if (!QCoreApplication::closingDown()) { diff --git a/src/platforms/mirserver/qmirserver_p.cpp b/src/platforms/mirserver/qmirserver_p.cpp index 29f24cc..5086558 100644 --- a/src/platforms/mirserver/qmirserver_p.cpp +++ b/src/platforms/mirserver/qmirserver_p.cpp @@ -19,7 +19,6 @@ // local #include "qmirserver_p.h" -#include <QDebug> /* FIXME: QThread by default starts an event loop, which is required for correct signal/slot * messaging between threads. However below you'll see that the mir server run() method @@ -27,7 +26,7 @@ * the queued signal/slot mechanism does not work. As workaround, need to use direct call to * stop the server. */ -void MirServerWorker::run() +void MirServerThread::run() { auto const main_loop = server->the_main_loop(); // By enqueuing the notification code in the main loop, we are @@ -43,16 +42,15 @@ void MirServerWorker::run() }); server->run(); // blocks until Mir server stopped - qDebug() << "stopped"; Q_EMIT stopped(); } -void MirServerWorker::stop() -{qDebug() << "stop"; +void MirServerThread::stop() +{ server->stop(); } -bool MirServerWorker::waitForMirStartup() +bool MirServerThread::waitForMirStartup() { std::unique_lock<decltype(mutex)> lock(mutex); started_cv.wait_for(lock, std::chrono::seconds{10}, [&]{ return mir_running; }); diff --git a/src/platforms/mirserver/qmirserver_p.h b/src/platforms/mirserver/qmirserver_p.h index d5c0a96..6e86d8d 100644 --- a/src/platforms/mirserver/qmirserver_p.h +++ b/src/platforms/mirserver/qmirserver_p.h @@ -29,23 +29,21 @@ #include "mirserver.h" class QMirServer; -class MirServerWorker; +class MirServerThread; struct QMirServerPrivate { QSharedPointer<MirServer> server; - QThread serverThread; - MirServerWorker *serverWorker; + MirServerThread *serverThread; }; -// Wraps mir::Server with QObject, so it can be controlled via QThread -class MirServerWorker : public QObject +class MirServerThread : public QThread { Q_OBJECT public: - MirServerWorker(const QSharedPointer<MirServer> &server) + MirServerThread(const QSharedPointer<MirServer> &server) : server(server) {} @@ -55,7 +53,7 @@ Q_SIGNALS: void stopped(); public Q_SLOTS: - void run(); + void run() override; void stop(); private: |