forked from qt-creator/qt-creator
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 <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -91,21 +91,25 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
|
||||
void ClangEditorDocumentParser::update(CppTools::WorkingCopy workingCopy)
|
||||
{
|
||||
QTC_ASSERT(m_marker, return);
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
QMutexLocker lock2(&m_mutex);
|
||||
QMutexLocker locker(&m_updateIsRunning);
|
||||
|
||||
m_projectPart = determineProjectPart();
|
||||
const QStringList options = createOptions(filePath(), projectPart(), true);
|
||||
// Determine project part
|
||||
State state_ = state();
|
||||
state_.projectPart = determineProjectPart(filePath(), configuration(), state_);
|
||||
setState(state_);
|
||||
|
||||
// Determine command line arguments
|
||||
const QStringList options = createOptions(filePath(), state_.projectPart, true);
|
||||
qCDebug(log, "Reparse options (cmd line equivalent): %s",
|
||||
commandLine(options, filePath()).toUtf8().constData());
|
||||
QTime t; t.start();
|
||||
|
||||
// Run
|
||||
QTime t; t.start();
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
m_marker->setFileName(filePath());
|
||||
m_marker->setCompilationOptions(options);
|
||||
const Internal::UnsavedFiles unsavedFiles = Utils::createUnsavedFiles(workingCopy);
|
||||
m_marker->reparse(unsavedFiles);
|
||||
|
||||
qCDebug(log) << "Reparse took" << t.elapsed() << "ms.";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user