forked from qt-creator/qt-creator
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 <eike.ziller@qt.io>
This commit is contained in:
@@ -174,17 +174,11 @@ bool HelpIndexFilter::updateCache(QFutureInterface<LocatorFilterEntry> &future,
|
||||
|
||||
QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &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();
|
||||
}
|
||||
|
@@ -29,10 +29,11 @@
|
||||
|
||||
#include <QIcon>
|
||||
#include <QMultiMap>
|
||||
#include <QMutex>
|
||||
#include <QSet>
|
||||
#include <QUrl>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user