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:
		@@ -31,7 +31,7 @@
 | 
			
		||||
#include "baseeditordocumentparser.h"
 | 
			
		||||
#include "baseeditordocumentprocessor.h"
 | 
			
		||||
 | 
			
		||||
#include "cppworkingcopy.h"
 | 
			
		||||
#include "cpptoolsreuse.h"
 | 
			
		||||
#include "editordocumenthandle.h"
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
@@ -81,10 +81,10 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
 | 
			
		||||
    m_configuration = configuration;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BaseEditorDocumentParser::update(WorkingCopy workingCopy)
 | 
			
		||||
void BaseEditorDocumentParser::update(const InMemoryInfo &info)
 | 
			
		||||
{
 | 
			
		||||
    QMutexLocker locker(&m_updateIsRunning);
 | 
			
		||||
    updateHelper(workingCopy);
 | 
			
		||||
    updateHelper(info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
 | 
			
		||||
@@ -147,4 +147,11 @@ ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(const QString &f
 | 
			
		||||
    return projectPart;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseEditorDocumentParser::InMemoryInfo::InMemoryInfo(bool withModifiedFiles)
 | 
			
		||||
    : workingCopy(CppTools::CppModelManager::instance()->workingCopy())
 | 
			
		||||
{
 | 
			
		||||
    if (withModifiedFiles)
 | 
			
		||||
        modifiedFiles = CppTools::modifiedFiles();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,7 @@
 | 
			
		||||
 | 
			
		||||
#include "cppmodelmanager.h"
 | 
			
		||||
#include "cpptools_global.h"
 | 
			
		||||
#include "cppworkingcopy.h"
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
@@ -59,7 +60,13 @@ public:
 | 
			
		||||
    Configuration configuration() const;
 | 
			
		||||
    void setConfiguration(const Configuration &configuration);
 | 
			
		||||
 | 
			
		||||
    void update(WorkingCopy workingCopy);
 | 
			
		||||
    struct CPPTOOLS_EXPORT InMemoryInfo {
 | 
			
		||||
        InMemoryInfo(bool withModifiedFiles);
 | 
			
		||||
 | 
			
		||||
        WorkingCopy workingCopy;
 | 
			
		||||
        Utils::FileNameList modifiedFiles;
 | 
			
		||||
    };
 | 
			
		||||
    void update(const InMemoryInfo &info);
 | 
			
		||||
 | 
			
		||||
    ProjectPart::Ptr projectPart() const;
 | 
			
		||||
 | 
			
		||||
@@ -78,7 +85,7 @@ protected:
 | 
			
		||||
    mutable QMutex m_stateAndConfigurationMutex;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    virtual void updateHelper(WorkingCopy workingCopy) = 0;
 | 
			
		||||
    virtual void updateHelper(const InMemoryInfo &inMemoryInfo) = 0;
 | 
			
		||||
 | 
			
		||||
    const QString m_filePath;
 | 
			
		||||
    Configuration m_configuration;
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@
 | 
			
		||||
#include "baseeditordocumentprocessor.h"
 | 
			
		||||
#include "cppworkingcopy.h"
 | 
			
		||||
 | 
			
		||||
#include "cpptoolsreuse.h"
 | 
			
		||||
#include "editordocumenthandle.h"
 | 
			
		||||
 | 
			
		||||
#include <utils/qtcassert.h>
 | 
			
		||||
@@ -118,7 +119,7 @@ QList<QTextEdit::ExtraSelection> BaseEditorDocumentProcessor::toTextEditorSelect
 | 
			
		||||
 | 
			
		||||
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
 | 
			
		||||
                                            BaseEditorDocumentParser *parser,
 | 
			
		||||
                                            WorkingCopy workingCopy)
 | 
			
		||||
                                            BaseEditorDocumentParser::InMemoryInfo info)
 | 
			
		||||
{
 | 
			
		||||
    future.setProgressRange(0, 1);
 | 
			
		||||
    if (future.isCanceled()) {
 | 
			
		||||
@@ -126,7 +127,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    parser->update(workingCopy);
 | 
			
		||||
    parser->update(info);
 | 
			
		||||
    CppModelManager::instance()
 | 
			
		||||
        ->finishedRefreshingSourceFiles(QSet<QString>() << parser->filePath());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -86,7 +86,7 @@ protected:
 | 
			
		||||
 | 
			
		||||
    static void runParser(QFutureInterface<void> &future,
 | 
			
		||||
                          CppTools::BaseEditorDocumentParser *parser,
 | 
			
		||||
                          CppTools::WorkingCopy workingCopy);
 | 
			
		||||
                          BaseEditorDocumentParser::InMemoryInfo info);
 | 
			
		||||
 | 
			
		||||
    // Convenience
 | 
			
		||||
    QString filePath() const { return m_baseTextDocument->filePath().toString(); }
 | 
			
		||||
 
 | 
			
		||||
@@ -44,16 +44,17 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath
 | 
			
		||||
    qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BuiltinEditorDocumentParser::updateHelper(WorkingCopy workingCopy)
 | 
			
		||||
void BuiltinEditorDocumentParser::updateHelper(const InMemoryInfo &info)
 | 
			
		||||
{
 | 
			
		||||
    if (filePath().isEmpty())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    const Configuration baseConfig = configuration();
 | 
			
		||||
    const bool releaseSourceAndAST_ = releaseSourceAndAST();
 | 
			
		||||
 | 
			
		||||
    State baseState = state();
 | 
			
		||||
    ExtraState state = extraState();
 | 
			
		||||
 | 
			
		||||
    if (filePath().isEmpty())
 | 
			
		||||
        return;
 | 
			
		||||
    WorkingCopy workingCopy = info.workingCopy;
 | 
			
		||||
 | 
			
		||||
    bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged_ = false;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -64,7 +64,7 @@ public:
 | 
			
		||||
    static BuiltinEditorDocumentParser *get(const QString &filePath);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void updateHelper(WorkingCopy workingCopy) override;
 | 
			
		||||
    void updateHelper(const InMemoryInfo &info) override;
 | 
			
		||||
    void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
 | 
			
		||||
                                QSet<Utils::FileName> *toRemove,
 | 
			
		||||
                                const Utils::FileName &fileName) const;
 | 
			
		||||
 
 | 
			
		||||
@@ -43,8 +43,8 @@
 | 
			
		||||
#include <cplusplus/CppDocument.h>
 | 
			
		||||
#include <cplusplus/SimpleLexer.h>
 | 
			
		||||
 | 
			
		||||
#include <utils/QtConcurrentTools>
 | 
			
		||||
#include <utils/qtcassert.h>
 | 
			
		||||
#include <utils/runextensions.h>
 | 
			
		||||
 | 
			
		||||
#include <QLoggingCategory>
 | 
			
		||||
 | 
			
		||||
@@ -166,7 +166,9 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
 | 
			
		||||
 | 
			
		||||
void BuiltinEditorDocumentProcessor::run()
 | 
			
		||||
{
 | 
			
		||||
    m_parserFuture = QtConcurrent::run(&runParser, parser(), CppTools::CppModelManager::instance()->workingCopy());
 | 
			
		||||
    m_parserFuture = QtConcurrent::run(&runParser,
 | 
			
		||||
                                       parser(),
 | 
			
		||||
                                       BuiltinEditorDocumentParser::InMemoryInfo(false));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseEditorDocumentParser *BuiltinEditorDocumentProcessor::parser()
 | 
			
		||||
 
 | 
			
		||||
@@ -162,7 +162,7 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
 | 
			
		||||
        // Parse the file as precisely as possible
 | 
			
		||||
        BuiltinEditorDocumentParser parser(file);
 | 
			
		||||
        parser.setReleaseSourceAndAST(false);
 | 
			
		||||
        parser.update(params.workingCopy);
 | 
			
		||||
        parser.update(BuiltinEditorDocumentParser::InMemoryInfo(false));
 | 
			
		||||
        CPlusPlus::Document::Ptr document = parser.document();
 | 
			
		||||
        QTC_ASSERT(document, return);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2188,7 +2188,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const
 | 
			
		||||
    m_gotCppSpecifics = true;
 | 
			
		||||
 | 
			
		||||
    if (BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(fileName())) {
 | 
			
		||||
        parser->update(m_workingCopy);
 | 
			
		||||
        parser->update(BuiltinEditorDocumentParser::InMemoryInfo(false));
 | 
			
		||||
        m_snapshot = parser->snapshot();
 | 
			
		||||
        m_headerPaths = parser->headerPaths();
 | 
			
		||||
        if (Document::Ptr document = parser->document())
 | 
			
		||||
 
 | 
			
		||||
@@ -915,7 +915,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
 | 
			
		||||
        BaseEditorDocumentParser::Configuration config = parser->configuration();
 | 
			
		||||
        config.usePrecompiledHeaders = true;
 | 
			
		||||
        parser->setConfiguration(config);
 | 
			
		||||
        parser->update(mm->workingCopy());
 | 
			
		||||
        parser->update(BuiltinEditorDocumentParser::InMemoryInfo(false));
 | 
			
		||||
 | 
			
		||||
        // Check if defines from pch are considered
 | 
			
		||||
        Document::Ptr document = mm->document(fileName);
 | 
			
		||||
@@ -998,8 +998,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
 | 
			
		||||
        BaseEditorDocumentParser::Configuration config = parser->configuration();
 | 
			
		||||
        config.editorDefines = editorDefines.toUtf8();
 | 
			
		||||
        parser->setConfiguration(config);
 | 
			
		||||
 | 
			
		||||
        parser->update(mm->workingCopy());
 | 
			
		||||
        parser->update(BuiltinEditorDocumentParser::InMemoryInfo(false));
 | 
			
		||||
 | 
			
		||||
        Document::Ptr doc = mm->document(main1File);
 | 
			
		||||
        QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,7 @@
 | 
			
		||||
 | 
			
		||||
#include "cpptoolsplugin.h"
 | 
			
		||||
 | 
			
		||||
#include <coreplugin/documentmanager.h>
 | 
			
		||||
#include <coreplugin/editormanager/editormanager.h>
 | 
			
		||||
#include <coreplugin/idocument.h>
 | 
			
		||||
#include <texteditor/convenience.h>
 | 
			
		||||
@@ -287,4 +288,13 @@ bool skipFileDueToSizeLimit(const QFileInfo &fileInfo, int limitInMB)
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Utils::FileNameList modifiedFiles()
 | 
			
		||||
{
 | 
			
		||||
    Utils::FileNameList files;
 | 
			
		||||
    foreach (Core::IDocument *doc, Core::DocumentManager::modifiedDocuments())
 | 
			
		||||
        files.append(doc->filePath());
 | 
			
		||||
    files.removeDuplicates();
 | 
			
		||||
    return files;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // CppTools
 | 
			
		||||
 
 | 
			
		||||
@@ -44,6 +44,10 @@ class QStringRef;
 | 
			
		||||
class QTextCursor;
 | 
			
		||||
QT_END_NAMESPACE
 | 
			
		||||
 | 
			
		||||
namespace Utils {
 | 
			
		||||
class FileNameList;
 | 
			
		||||
} // namespace Utils
 | 
			
		||||
 | 
			
		||||
namespace CPlusPlus {
 | 
			
		||||
class Macro;
 | 
			
		||||
class Symbol;
 | 
			
		||||
@@ -52,6 +56,8 @@ class LookupContext;
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
 | 
			
		||||
Utils::FileNameList CPPTOOLS_EXPORT modifiedFiles();
 | 
			
		||||
 | 
			
		||||
void CPPTOOLS_EXPORT moveCursorToEndOfIdentifier(QTextCursor *tc);
 | 
			
		||||
void CPPTOOLS_EXPORT moveCursorToStartOfIdentifier(QTextCursor *tc);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user