From 442bdbded2b2268efcb3be1a969d432533023366 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 7 Jul 2015 15:02:14 +0200 Subject: CppTools: Avoid unnecessary blocking of main thread Among others, BaseEditorDocumentParser::projectPart() was a blocking operation in case the parser was running. This led to noticeable GUI freezes for the ClangCodeModel since the function was called from the main thread. Rework *EditorDocumentParser to clearly separate the configuration data (input) from the actual object state. Querying/setting configuration or (last) state does not block anymore. update() is supposed to get the necessary configuration and the last state at the beginning and to set the new state at end. Change-Id: Ib4b534fa6ff373c3059826726b3f10ece95acc21 Reviewed-by: Erik Verbruggen --- src/plugins/cpptools/cpptoolstestcase.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp') diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 8d2a3684a0..8cd7953320 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -29,6 +29,10 @@ ****************************************************************************/ #include "cpptoolstestcase.h" + +#include "baseeditordocumentparser.h" +#include "baseeditordocumentprocessor.h" +#include "editordocumenthandle.h" #include "cppmodelmanager.h" #include "cppworkingcopy.h" @@ -140,6 +144,31 @@ bool TestCase::garbageCollectGlobalSnapshot() return globalSnapshot().isEmpty(); } +static bool waitForProcessedEditorDocument_internal(CppEditorDocumentHandle *editorDocument, + int timeOutInMs) +{ + QTC_ASSERT(editorDocument, return false); + + QTime timer; + timer.start(); + + forever { + if (!editorDocument->processor()->isParserRunning()) + return true; + if (timer.elapsed() > timeOutInMs) + return false; + + QCoreApplication::processEvents(); + QThread::msleep(20); + } +} + +bool TestCase::waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs) +{ + auto *editorDocument = CppModelManager::instance()->cppEditorDocument(filePath); + return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs); +} + bool TestCase::parseFiles(const QSet &filePaths) { CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); -- cgit v1.2.1