Commit 5902a622 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Let BaseEditorDocumentParser acquire the mutex

...so derived classes are freed from doing this.

Change-Id: I73f3eca54be14cfd6542a466f0e9c024457bef07
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 442bdbde
......@@ -88,10 +88,9 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
{
}
void ClangEditorDocumentParser::update(CppTools::WorkingCopy workingCopy)
void ClangEditorDocumentParser::updateHelper(CppTools::WorkingCopy workingCopy)
{
QTC_ASSERT(m_marker, return);
QMutexLocker locker(&m_updateIsRunning);
// Determine project part
State state_ = state();
......
......@@ -46,13 +46,13 @@ class ClangEditorDocumentParser : public CppTools::BaseEditorDocumentParser
public:
ClangEditorDocumentParser(const QString &filePath);
void update(CppTools::WorkingCopy workingCopy) override;
QList<Diagnostic> diagnostics() const;
QList<SemanticMarker::Range> ifdefedOutBlocks() const;
SemanticMarker::Ptr semanticMarker() const;
private:
void updateHelper(CppTools::WorkingCopy workingCopy) override;
SemanticMarker::Ptr m_marker;
};
......
......@@ -31,6 +31,7 @@
#include "baseeditordocumentparser.h"
#include "baseeditordocumentprocessor.h"
#include "cppworkingcopy.h"
#include "editordocumenthandle.h"
namespace CppTools {
......@@ -44,14 +45,13 @@ namespace CppTools {
It's meant to be used in the C++ editor to get precise results by using
the "best" project part for a file.
Derived classes are expected to implement update() this way:
Derived classes are expected to implement updateHelper() this way:
\list
\li Get a copy of the configuration and the last state.
\li Acquire the protected m_updateIsRunning for the duration of update().
\li Work on the data and do whatever is necessary. At least, update
the project part with the help of determineProjectPart().
\li Ensure the new state is set before update() returns.
\li Ensure the new state is set before updateHelper() returns.
\endlist
*/
......@@ -81,6 +81,12 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
m_configuration = configuration;
}
void BaseEditorDocumentParser::update(WorkingCopy workingCopy)
{
QMutexLocker locker(&m_updateIsRunning);
updateHelper(workingCopy);
}
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
{
QMutexLocker locker(&m_stateAndConfigurationMutex);
......
......@@ -56,11 +56,10 @@ public:
virtual ~BaseEditorDocumentParser();
QString filePath() const;
Configuration configuration() const;
void setConfiguration(const Configuration &configuration);
virtual void update(WorkingCopy workingCopy) = 0;
void update(WorkingCopy workingCopy);
ProjectPart::Ptr projectPart() const;
......@@ -69,7 +68,6 @@ protected:
QByteArray editorDefines;
ProjectPart::Ptr projectPart;
};
State state() const;
void setState(const State &state);
......@@ -77,14 +75,15 @@ protected:
const Configuration &config,
const State &state);
mutable QMutex m_updateIsRunning;
mutable QMutex m_stateAndConfigurationMutex;
private:
const QString m_filePath;
virtual void updateHelper(WorkingCopy workingCopy) = 0;
const QString m_filePath;
Configuration m_configuration;
State m_state;
mutable QMutex m_updateIsRunning;
};
} // namespace CppTools
......
......@@ -44,10 +44,8 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath
qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
}
void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
void BuiltinEditorDocumentParser::updateHelper(WorkingCopy workingCopy)
{
QMutexLocker locker(&m_updateIsRunning);
const Configuration baseConfig = configuration();
const bool releaseSourceAndAST_ = releaseSourceAndAST();
......
......@@ -51,8 +51,6 @@ public:
bool releaseSourceAndAST() const;
void setReleaseSourceAndAST(bool release);
void update(WorkingCopy workingCopy) override;
CPlusPlus::Document::Ptr document() const;
CPlusPlus::Snapshot snapshot() const;
ProjectPart::HeaderPaths headerPaths() const;
......@@ -66,6 +64,7 @@ public:
static BuiltinEditorDocumentParser *get(const QString &filePath);
private:
void updateHelper(WorkingCopy workingCopy) override;
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
QSet<Utils::FileName> *toRemove,
const Utils::FileName &fileName) const;
......@@ -80,7 +79,6 @@ private:
CPlusPlus::Snapshot snapshot;
bool forceSnapshotInvalidation = false;
};
ExtraState extraState() const;
void setExtraState(const ExtraState &extraState);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment