ClassView: Don't lock the mutex while parsing

When parsing is being done we are producing a new
ParserTreeItem structure from scratch. This includes
creating new ParserTreeItems or getting data from
caches. So, we are not interferring with the
data stored in the rootItem. After the rootItem
is set, Parser doesn't modify this structure
anymore. There is no need to protect the parsing
with the mutex, as only 3 methods which are called
concurrently operate only on the rootItem: fetchMore(),
canFetchMore() and hasChildren(). Instead, we
protect only the process of setting the rootItem
to the new value. Similarly, we protect only
the process of reading the rootItem inside
findItemByRoot().

Task-number: QTCREATORBUG-25317
Change-Id: Ieda10107137f5031a81d67f2d608a90f6e72902d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2021-02-15 10:14:33 +01:00
parent cc6df4e707
commit 0907315f47

View File

@@ -230,10 +230,11 @@ ParserTreeItem::ConstPtr Parser::findItemByRoot(const QStandardItem *item, bool
if (skipRoot && uiList.count() > 0) if (skipRoot && uiList.count() > 0)
uiList.removeLast(); uiList.removeLast();
QReadLocker locker(&d->rootItemLocker); ParserTreeItem::ConstPtr internal;
{
// using internal root - search correct item QReadLocker locker(&d->rootItemLocker);
ParserTreeItem::ConstPtr internal = d->rootItem; internal = d->rootItem;
}
while (uiList.count() > 0) { while (uiList.count() > 0) {
cur = uiList.last(); cur = uiList.last();
@@ -588,13 +589,13 @@ void Parser::requestCurrentState()
{ {
d->timer.stop(); d->timer.stop();
d->rootItemLocker.lockForWrite(); const ParserTreeItem::ConstPtr newRoot = parse();
d->rootItem = parse(); {
d->rootItemLocker.unlock(); QWriteLocker locker(&d->rootItemLocker);
d->rootItem = newRoot;
}
// convert
QSharedPointer<QStandardItem> std(new QStandardItem()); QSharedPointer<QStandardItem> std(new QStandardItem());
d->rootItem->convertTo(std.data()); d->rootItem->convertTo(std.data());
emit treeDataUpdate(std); emit treeDataUpdate(std);