forked from qt-creator/qt-creator
Clang: Do not call DocumentManager::modifiedDocuments() from worker thread
This is unsafe. Change-Id: I8ac075a7289afa0d84785e37b1325d186a153000 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
@@ -58,7 +59,9 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(
|
||||
, m_languageFeatures(features)
|
||||
, m_textEditorWidget(textEditorWidget)
|
||||
{
|
||||
m_unsavedFiles = Utils::createUnsavedFiles(CppTools::CppModelManager::instance()->workingCopy());
|
||||
m_unsavedFiles = Utils::createUnsavedFiles(
|
||||
CppTools::CppModelManager::instance()->workingCopy(),
|
||||
CppTools::modifiedFiles());
|
||||
}
|
||||
|
||||
bool ClangCompletionAssistInterface::objcEnabled() const
|
||||
|
||||
@@ -88,7 +88,7 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
|
||||
{
|
||||
}
|
||||
|
||||
void ClangEditorDocumentParser::updateHelper(CppTools::WorkingCopy workingCopy)
|
||||
void ClangEditorDocumentParser::updateHelper(const BaseEditorDocumentParser::InMemoryInfo &info)
|
||||
{
|
||||
QTC_ASSERT(m_marker, return);
|
||||
|
||||
@@ -107,7 +107,8 @@ void ClangEditorDocumentParser::updateHelper(CppTools::WorkingCopy workingCopy)
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
m_marker->setFileName(filePath());
|
||||
m_marker->setCompilationOptions(options);
|
||||
const Internal::UnsavedFiles unsavedFiles = Utils::createUnsavedFiles(workingCopy);
|
||||
const Internal::UnsavedFiles unsavedFiles = Utils::createUnsavedFiles(info.workingCopy,
|
||||
info.modifiedFiles);
|
||||
m_marker->reparse(unsavedFiles);
|
||||
qCDebug(log) << "Reparse took" << t.elapsed() << "ms.";
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
SemanticMarker::Ptr semanticMarker() const;
|
||||
|
||||
private:
|
||||
void updateHelper(CppTools::WorkingCopy workingCopy) override;
|
||||
void updateHelper(const BaseEditorDocumentParser::InMemoryInfo &info) override;
|
||||
|
||||
SemanticMarker::Ptr m_marker;
|
||||
};
|
||||
|
||||
@@ -144,9 +144,6 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
|
||||
void ClangEditorDocumentProcessor::run()
|
||||
{
|
||||
// Run clang parser
|
||||
const CppTools::WorkingCopy workingCopy
|
||||
= CppTools::CppModelManager::instance()->workingCopy();
|
||||
|
||||
disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
||||
this, &ClangEditorDocumentProcessor::onParserFinished);
|
||||
m_parserWatcher.cancel();
|
||||
@@ -155,7 +152,9 @@ void ClangEditorDocumentProcessor::run()
|
||||
m_parserRevision = revision();
|
||||
connect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
||||
this, &ClangEditorDocumentProcessor::onParserFinished);
|
||||
const QFuture<void> future = QtConcurrent::run(&runParser, parser(), workingCopy);
|
||||
const QFuture<void> future = QtConcurrent::run(&runParser,
|
||||
parser(),
|
||||
ClangEditorDocumentParser::InMemoryInfo(true));
|
||||
m_parserWatcher.setFuture(future);
|
||||
|
||||
// Run builtin processor
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
@@ -58,15 +57,9 @@ namespace Utils {
|
||||
|
||||
Q_LOGGING_CATEGORY(verboseRunLog, "qtc.clangcodemodel.verboserun")
|
||||
|
||||
UnsavedFiles createUnsavedFiles(WorkingCopy workingCopy)
|
||||
UnsavedFiles createUnsavedFiles(const WorkingCopy &workingCopy,
|
||||
const ::Utils::FileNameList &modifiedFiles)
|
||||
{
|
||||
// TODO: change the modelmanager to hold one working copy, and amend it every time we ask for one.
|
||||
// TODO: Reason: the UnsavedFile needs a QByteArray.
|
||||
|
||||
QSet< ::Utils::FileName> modifiedFiles;
|
||||
foreach (IDocument *doc, DocumentManager::modifiedDocuments())
|
||||
modifiedFiles.insert(doc->filePath());
|
||||
|
||||
UnsavedFiles result;
|
||||
QHashIterator< ::Utils::FileName, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator();
|
||||
while (wcIter.hasNext()) {
|
||||
|
||||
@@ -43,7 +43,9 @@ namespace Utils {
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(verboseRunLog)
|
||||
|
||||
ClangCodeModel::Internal::UnsavedFiles createUnsavedFiles(CppTools::WorkingCopy workingCopy);
|
||||
ClangCodeModel::Internal::UnsavedFiles createUnsavedFiles(
|
||||
const CppTools::WorkingCopy &workingCopy,
|
||||
const ::Utils::FileNameList &modifiedFiles);
|
||||
|
||||
QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart,
|
||||
CppTools::ProjectFile::Kind fileKind);
|
||||
|
||||
Reference in New Issue
Block a user