forked from qt-creator/qt-creator
ClassView: Get rid of project and document mutexes
In fact, all the methods inside Parser class are called only in one thread (parser thread), which runs his own event loop. The exception is 3 methods (canFetchMore(), fetchMore() and hasChildren()), which may be called concurrently from the main thread. However, they are protected with another mutex. So, project and document mutex were protecting the access to internals only when called from one, always the same thread, what is not needed at all. Task-number: QTCREATORBUG-25317 Change-Id: I0b44b762b5d76d003035e9c3099c90568b7faf80 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -97,9 +97,6 @@ public:
|
|||||||
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|
||||||
QReadWriteLock m_documentLock;
|
|
||||||
QReadWriteLock m_projectLock;
|
|
||||||
|
|
||||||
struct DocumentCache {
|
struct DocumentCache {
|
||||||
unsigned treeRevision = 0;
|
unsigned treeRevision = 0;
|
||||||
ParserTreeItem::Ptr tree;
|
ParserTreeItem::Ptr tree;
|
||||||
@@ -383,7 +380,6 @@ ParserTreeItem::Ptr Parser::getParseProjectTree(const QStringList &fileList,
|
|||||||
ParserTreeItem::Ptr item(new ParserTreeItem());
|
ParserTreeItem::Ptr item(new ParserTreeItem());
|
||||||
unsigned revision = 0;
|
unsigned revision = 0;
|
||||||
foreach (const QString &file, fileList) {
|
foreach (const QString &file, fileList) {
|
||||||
// ? locker for document?..
|
|
||||||
const CPlusPlus::Document::Ptr &doc = d->document(file);
|
const CPlusPlus::Document::Ptr &doc = d->document(file);
|
||||||
if (doc.isNull())
|
if (doc.isNull())
|
||||||
continue;
|
continue;
|
||||||
@@ -400,8 +396,6 @@ ParserTreeItem::Ptr Parser::getParseProjectTree(const QStringList &fileList,
|
|||||||
|
|
||||||
// update the cache
|
// update the cache
|
||||||
if (!projectId.isEmpty()) {
|
if (!projectId.isEmpty()) {
|
||||||
QWriteLocker locker(&d->m_projectLock);
|
|
||||||
|
|
||||||
ParserPrivate::ProjectCache &projectCache = d->m_projectCache[projectId];
|
ParserPrivate::ProjectCache &projectCache = d->m_projectCache[projectId];
|
||||||
projectCache.tree = item;
|
projectCache.tree = item;
|
||||||
projectCache.treeRevision = revision;
|
projectCache.treeRevision = revision;
|
||||||
@@ -418,8 +412,6 @@ ParserTreeItem::Ptr Parser::getParseProjectTree(const QStringList &fileList,
|
|||||||
ParserTreeItem::Ptr Parser::getCachedOrParseProjectTree(const QStringList &fileList,
|
ParserTreeItem::Ptr Parser::getCachedOrParseProjectTree(const QStringList &fileList,
|
||||||
const QString &projectId)
|
const QString &projectId)
|
||||||
{
|
{
|
||||||
QReadLocker locker(&d->m_projectLock);
|
|
||||||
|
|
||||||
const auto it = d->m_projectCache.constFind(projectId);
|
const auto it = d->m_projectCache.constFind(projectId);
|
||||||
if (it != d->m_projectCache.constEnd() && !it.value().tree.isNull()) {
|
if (it != d->m_projectCache.constEnd() && !it.value().tree.isNull()) {
|
||||||
// calculate project's revision
|
// calculate project's revision
|
||||||
@@ -436,7 +428,6 @@ ParserTreeItem::Ptr Parser::getCachedOrParseProjectTree(const QStringList &fileL
|
|||||||
return it.value().tree;
|
return it.value().tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
locker.unlock();
|
|
||||||
return getParseProjectTree(fileList, projectId);
|
return getParseProjectTree(fileList, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +453,6 @@ ParserTreeItem::ConstPtr Parser::getParseDocumentTree(const CPlusPlus::Document:
|
|||||||
for (unsigned i = 0; i < total; ++i)
|
for (unsigned i = 0; i < total; ++i)
|
||||||
addSymbol(itemPtr, doc->globalSymbolAt(i));
|
addSymbol(itemPtr, doc->globalSymbolAt(i));
|
||||||
|
|
||||||
QWriteLocker locker(&d->m_documentLock);
|
|
||||||
d->m_documentCache.insert(fileName, { doc->revision(), itemPtr, doc } );
|
d->m_documentCache.insert(fileName, { doc->revision(), itemPtr, doc } );
|
||||||
return itemPtr;
|
return itemPtr;
|
||||||
}
|
}
|
||||||
@@ -480,13 +470,10 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::D
|
|||||||
return ParserTreeItem::ConstPtr();
|
return ParserTreeItem::ConstPtr();
|
||||||
|
|
||||||
const QString &fileName = doc->fileName();
|
const QString &fileName = doc->fileName();
|
||||||
{
|
const auto it = d->m_documentCache.constFind(fileName);
|
||||||
QReadLocker locker(&d->m_documentLock);
|
if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull()
|
||||||
const auto it = d->m_documentCache.constFind(fileName);
|
&& it.value().treeRevision == doc->revision()) {
|
||||||
if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull()
|
return it.value().tree;
|
||||||
&& it.value().treeRevision == doc->revision()) {
|
|
||||||
return it.value().tree;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return getParseDocumentTree(doc);
|
return getParseDocumentTree(doc);
|
||||||
}
|
}
|
||||||
@@ -533,8 +520,6 @@ void Parser::removeFiles(const QStringList &fileList)
|
|||||||
if (fileList.isEmpty())
|
if (fileList.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QWriteLocker projectLocker(&d->m_projectLock);
|
|
||||||
QWriteLocker documentLocker(&d->m_documentLock);
|
|
||||||
for (const QString &name : fileList) {
|
for (const QString &name : fileList) {
|
||||||
d->fileList.remove(name);
|
d->fileList.remove(name);
|
||||||
d->m_documentCache.remove(name);
|
d->m_documentCache.remove(name);
|
||||||
@@ -549,14 +534,10 @@ void Parser::removeFiles(const QStringList &fileList)
|
|||||||
*/
|
*/
|
||||||
void Parser::resetData(const CPlusPlus::Snapshot &snapshot)
|
void Parser::resetData(const CPlusPlus::Snapshot &snapshot)
|
||||||
{
|
{
|
||||||
{
|
d->m_projectCache.clear();
|
||||||
QWriteLocker projectLocker(&d->m_projectLock);
|
d->m_documentCache.clear();
|
||||||
QWriteLocker documentLocker(&d->m_documentLock);
|
for (auto it = snapshot.begin(); it != snapshot.end(); ++it)
|
||||||
d->m_projectCache.clear();
|
d->m_documentCache[it.key().toString()].document = it.value();
|
||||||
d->m_documentCache.clear();
|
|
||||||
for (auto it = snapshot.begin(); it != snapshot.end(); ++it)
|
|
||||||
d->m_documentCache[it.key().toString()].document = it.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
// recalculate file list
|
// recalculate file list
|
||||||
FilePaths fileList;
|
FilePaths fileList;
|
||||||
|
|||||||
Reference in New Issue
Block a user