diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 39 | ||||
| -rw-r--r-- | src/mainwindow.h | 4 |
2 files changed, 21 insertions, 22 deletions
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<void> 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<QObject>()) { - IPlugin *plugin = qobject_cast<IPlugin*>(pluginObj); - if (plugin == nullptr || plugin->isActive()) { - IPluginDiagnose *diagnose = qobject_cast<IPluginDiagnose*>(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<QObject>()) { + IPlugin *plugin = qobject_cast<IPlugin*>(pluginObj); + if (plugin == nullptr || plugin->isActive()) { + IPluginDiagnose *diagnose = qobject_cast<IPluginDiagnose*>(pluginObj); + if (diagnose != nullptr) + numProblems += diagnose->activeProblems().size(); + } } + m_NumberOfProblems = numProblems; + emit checkForProblemsDone(); } - m_NumberOfProblems = numProblems; - m_CheckingForProblems = false; - emit checkForProblemsDone(); } void MainWindow::about() diff --git a/src/mainwindow.h b/src/mainwindow.h index 14987c0d..94626ff3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -360,8 +360,8 @@ private: QIcon m_originalNotificationIcon; std::atomic<std::size_t> m_NumberOfProblems; - std::atomic<bool> m_CheckingForProblems; - QMutex m_CheckForProblemsMutex; + std::atomic<bool> m_ProblemsCheckRequired; + std::mutex m_CheckForProblemsMutex; Executable* getSelectedExecutable(); |
