From 0907315f476a0b393753ced04b7a22478b81dc6e Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 15 Feb 2021 10:14:33 +0100 Subject: [PATCH] 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 --- src/plugins/classview/classviewparser.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index 3022a8071e8..b56baba0724 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -230,10 +230,11 @@ ParserTreeItem::ConstPtr Parser::findItemByRoot(const QStandardItem *item, bool if (skipRoot && uiList.count() > 0) uiList.removeLast(); - QReadLocker locker(&d->rootItemLocker); - - // using internal root - search correct item - ParserTreeItem::ConstPtr internal = d->rootItem; + ParserTreeItem::ConstPtr internal; + { + QReadLocker locker(&d->rootItemLocker); + internal = d->rootItem; + } while (uiList.count() > 0) { cur = uiList.last(); @@ -588,13 +589,13 @@ void Parser::requestCurrentState() { d->timer.stop(); - d->rootItemLocker.lockForWrite(); - d->rootItem = parse(); - d->rootItemLocker.unlock(); + const ParserTreeItem::ConstPtr newRoot = parse(); + { + QWriteLocker locker(&d->rootItemLocker); + d->rootItem = newRoot; + } - // convert QSharedPointer std(new QStandardItem()); - d->rootItem->convertTo(std.data()); emit treeDataUpdate(std);