From cafd724aaf52f9b38d437918a0ec5f97cf92a742 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 16 Oct 2016 16:57:42 +0100 Subject: [PATCH] Performance: avoid long sleep in processEvents loop. --- src/blackcore/application.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 42019170e..f89a03a17 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -248,14 +248,10 @@ namespace BlackCore bool CApplication::waitForStart() { - // process events return immediatley if nothing is to be processed - const QTime dieTime = QTime::currentTime().addMSecs(5000); - while (QTime::currentTime() < dieTime && !this->m_started && !this->m_startUpCompleted) - { - // Alternative: use QEventLoop, which seemed to make the scenario here more complex - QCoreApplication::instance()->processEvents(QEventLoop::AllEvents, 250); - QThread::msleep(250); // avoid CPU loop overload by "infinite loop" - } + QEventLoop eventLoop; + QTimer::singleShot(5000, &eventLoop, &QEventLoop::quit); + connect(this, &CApplication::setupAvailable, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); if (!this->m_startUpCompleted) { CLogMessage(this).error("Waiting for startup timed out");