From 8d06e66c49237ecee9c04ef6bde60f4251073e0f Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 29 Jan 2021 17:25:21 +0100 Subject: [PATCH] HelpIndexFilter: use atomic_bool for the m_needsUpdate field This will simplify the code, no need for mutex anymore. Change-Id: I85e0cad7ed3b3288ae1eec03f7504590293c4ea5 Reviewed-by: Eike Ziller --- src/plugins/help/helpindexfilter.cpp | 10 +--------- src/plugins/help/helpindexfilter.h | 6 +++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index 693d56dbb32..6fe2f713745 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -174,17 +174,11 @@ bool HelpIndexFilter::updateCache(QFutureInterface &future, QList HelpIndexFilter::matchesFor(QFutureInterface &future, const QString &entry) { - m_mutex.lock(); // guard m_needsUpdate - bool forceUpdate = m_needsUpdate; - m_mutex.unlock(); - - if (forceUpdate) { + if (m_needsUpdate) { QStringList indices; QMetaObject::invokeMethod(this, [this] { return allIndices(); }, Qt::BlockingQueuedConnection, &indices); - m_mutex.lock(); // guard m_needsUpdate m_needsUpdate = false; - m_mutex.unlock(); m_allIndicesCache = indices; // force updating the cache taking the m_allIndicesCache m_lastIndicesCache = QStringList(); @@ -279,7 +273,5 @@ QStringList HelpIndexFilter::allIndices() const void HelpIndexFilter::invalidateCache() { - m_mutex.lock(); m_needsUpdate = true; - m_mutex.unlock(); } diff --git a/src/plugins/help/helpindexfilter.h b/src/plugins/help/helpindexfilter.h index 9d8e893dc8c..910e19cd37b 100644 --- a/src/plugins/help/helpindexfilter.h +++ b/src/plugins/help/helpindexfilter.h @@ -29,10 +29,11 @@ #include #include -#include #include #include +#include + namespace Help { namespace Internal { @@ -77,8 +78,7 @@ private: QStringList m_lastIndicesCache; QString m_lastEntry; #endif - bool m_needsUpdate = true; - QMutex m_mutex; + std::atomic_bool m_needsUpdate = true; QIcon m_icon; };