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)
|
QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
||||||
{
|
{
|
||||||
m_mutex.lock(); // guard m_needsUpdate
|
if (m_needsUpdate) {
|
||||||
bool forceUpdate = m_needsUpdate;
|
|
||||||
m_mutex.unlock();
|
|
||||||
|
|
||||||
if (forceUpdate) {
|
|
||||||
QStringList indices;
|
QStringList indices;
|
||||||
QMetaObject::invokeMethod(this, [this] { return allIndices(); },
|
QMetaObject::invokeMethod(this, [this] { return allIndices(); },
|
||||||
Qt::BlockingQueuedConnection, &indices);
|
Qt::BlockingQueuedConnection, &indices);
|
||||||
m_mutex.lock(); // guard m_needsUpdate
|
|
||||||
m_needsUpdate = false;
|
m_needsUpdate = false;
|
||||||
m_mutex.unlock();
|
|
||||||
m_allIndicesCache = indices;
|
m_allIndicesCache = indices;
|
||||||
// force updating the cache taking the m_allIndicesCache
|
// force updating the cache taking the m_allIndicesCache
|
||||||
m_lastIndicesCache = QStringList();
|
m_lastIndicesCache = QStringList();
|
||||||
@@ -279,7 +273,5 @@ QStringList HelpIndexFilter::allIndices() const
|
|||||||
|
|
||||||
void HelpIndexFilter::invalidateCache()
|
void HelpIndexFilter::invalidateCache()
|
||||||
{
|
{
|
||||||
m_mutex.lock();
|
|
||||||
m_needsUpdate = true;
|
m_needsUpdate = true;
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
@@ -29,10 +29,11 @@
|
|||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMultiMap>
|
#include <QMultiMap>
|
||||||
#include <QMutex>
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace Help {
|
namespace Help {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -77,8 +78,7 @@ private:
|
|||||||
QStringList m_lastIndicesCache;
|
QStringList m_lastIndicesCache;
|
||||||
QString m_lastEntry;
|
QString m_lastEntry;
|
||||||
#endif
|
#endif
|
||||||
bool m_needsUpdate = true;
|
std::atomic_bool m_needsUpdate = true;
|
||||||
QMutex m_mutex;
|
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user