From d845fe9a74c9e0943defe5025b81c017a3fab41b Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sun, 7 Jun 2020 18:51:02 +0200 Subject: Make checks that occur at the same time not return immediately to avoid issues with stuff that might need to rely on check completion. --- src/mainwindow.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4a5175e6..1a868eec 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -267,7 +267,7 @@ MainWindow::MainWindow(Settings &settings , m_LinkDesktop(nullptr) , m_LinkStartMenu(nullptr) , m_NumberOfProblems(0) - , m_CheckingForProblems(false) + , m_ProblemsCheckRequired(false) { // disables incredibly slow menu fade in effect that looks and feels like crap. // this was only happening to users with the windows @@ -1107,27 +1107,26 @@ QFuture MainWindow::checkForProblemsAsync() { void MainWindow::checkForProblemsImpl() { TimeThis tt("MainWindow::checkForProblemsImpl()"); - { - QMutexLocker lk(&m_CheckForProblemsMutex); - if (m_CheckingForProblems) { - return; - } - else { - m_CheckingForProblems = true; - } - } - size_t numProblems = 0; - for (QObject *pluginObj : m_PluginContainer.plugins()) { - IPlugin *plugin = qobject_cast(pluginObj); - if (plugin == nullptr || plugin->isActive()) { - IPluginDiagnose *diagnose = qobject_cast(pluginObj); - if (diagnose != nullptr) - numProblems += diagnose->activeProblems().size(); + + m_ProblemsCheckRequired = true; + + std::scoped_lock lk(m_CheckForProblemsMutex); + + // another thread might already have checked while this one was waiting on the lock + if (m_ProblemsCheckRequired) { + m_ProblemsCheckRequired = false; + size_t numProblems = 0; + for (QObject *pluginObj : m_PluginContainer.plugins()) { + IPlugin *plugin = qobject_cast(pluginObj); + if (plugin == nullptr || plugin->isActive()) { + IPluginDiagnose *diagnose = qobject_cast(pluginObj); + if (diagnose != nullptr) + numProblems += diagnose->activeProblems().size(); + } } + m_NumberOfProblems = numProblems; + emit checkForProblemsDone(); } - m_NumberOfProblems = numProblems; - m_CheckingForProblems = false; - emit checkForProblemsDone(); } void MainWindow::about() -- cgit v1.3.1