Commit 9b2672cb authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen
Browse files

CppTools: Fix data race when accessing the editor revision

Addresses the following findings of QTCREATORBUG-12030:
 * qtc.helgrind.plugintests.txt#2
 * qtc.helgrind.usingEditors1.txt#1

Helgrind report (truncated):

Possible data race during write of size 4 at 0x23679618 by thread #1
Locks held: none
   at 0x6819003: ???
   by 0x681D713: ???
   by 0x68200DE: ???
   by 0x684B8F8: QTextCursor::insertText(QString const&, QTextCharFormat const&)
   by 0x684BCB9: QTextCursor::insertText(QString const&)
   by 0x139DA06C: TextEditor::BaseTextEditorWidget::keyPressEvent(QKeyEvent*) (basetexteditor.cpp:1866)
   by 0x184C999F: CppEditor::Internal::CPPEditorWidget::keyPressEvent(QKeyEvent*) (cppeditor.cpp:1416)

This conflicts with a previous read of size 4 by thread #18
Locks held: none
   at 0x680BC54: QTextDocument::revision() const
   by 0x159047F3: CppTools::CppEditorSupport::editorRevision() const (cpptoolseditorsupport.cpp:198)
   by 0x158E39BF: CppTools::Internal::CppModelManager::buildWorkingCopyList() (cppmodelmanager.cpp:525)
   by 0x158E3D5B: CppTools::Internal::CppModelManager::workingCopy() const (cppmodelmanager.cpp:544)
   by 0x1589FF6F: CppTools::Internal::CppCompletionAssistInterface::getCppSpecifics() const (cppcompletionassist.cpp:1957)
   by 0x158A1158: CppTools::Internal::CppCompletionAssistInterface::snapshot() const (cppcompletionassist.h:200)
   by 0x1589707C: CppTools::Internal::CppCompletionAssistProcessor::startCompletionInternal(QString, unsigned int, unsigned int, QString const&, int) (cppcompletionassist.cpp:1212)
   by 0x15893CC7: CppTools::Internal::CppCompletionAssistProcessor::startCompletionHelper() (cppcompletionassist.cpp:970)

---

Possible data race during write of size 4 at 0x24C8AD18 by thread #1


Locks held: none
   at 0x684AF23: QTextCursor::beginEditBlock()
   by 0x139D7D05: TextEditor::BaseTextEditorWidget::keyPressEvent(QKeyEvent*) (basetexteditor.cpp:1578)
   by 0x184C999F: CppEditor::Internal::CPPEditorWidget::keyPressEvent(QKeyEvent*) (cppeditor.cpp:1416)
   ...
   by 0x40F15A: main (main.cpp:533)

This conflicts with a previous read of size 4 by thread #11
Locks held: none
   at 0x680BC54: QTextDocument::revision() const
   by 0x159048D3: CppTools::CppEditorSupport::editorRevision() const (cpptoolseditorsupport.cpp:198)
   by 0x158E3A9F: CppTools::Internal::CppModelManager::buildWorkingCopyList() (cppmodelmanager.cpp:525)
   by 0x158E3E3B: CppTools::Internal::CppModelManager::workingCopy() const (cppmodelmanager.cpp:544)
   by 0x1590741E: parse(QFutureInterface<void>&, QSharedPointer<CppTools::SnapshotUpdater>) (cpptoolseditorsupport.cpp:299)

Task-number: QTCREATORBUG-12030
Change-Id: Idf0aa47f1f6bfd6814a961fe39d3b19b98f934f5
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 291b80cb
......@@ -427,7 +427,10 @@ TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInte
Q_UNUSED(project);
QTC_ASSERT(editor, return 0);
QTC_ASSERT(document, return 0);
return new CppTools::Internal::CppCompletionAssistInterface(editor, document, position, reason);
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
return new CppTools::Internal::CppCompletionAssistInterface(editor, document, position, reason,
modelManager->workingCopy());
}
// -----------------
......@@ -1954,7 +1957,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
if (CppEditorSupport *supp = modelManager->cppEditorSupport(m_editor)) {
if (QSharedPointer<SnapshotUpdater> updater = supp->snapshotUpdater()) {
updater->update(modelManager->workingCopy());
updater->update(m_workingCopy);
m_snapshot = updater->snapshot();
m_includePaths = updater->includePaths();
m_frameworkPaths = updater->frameworkPaths();
......
......@@ -31,6 +31,7 @@
#define CPPCOMPLETIONASSIST_H
#include "cppcompletionassistprovider.h"
#include "cppmodelmanagerinterface.h"
#include <cplusplus/Icons.h>
#include <cplusplus/TypeOfExpression.h>
......@@ -175,11 +176,13 @@ public:
CppCompletionAssistInterface(TextEditor::BaseTextEditor *editor,
QTextDocument *textDocument,
int position,
TextEditor::AssistReason reason)
TextEditor::AssistReason reason,
const CppModelManagerInterface::WorkingCopy &workingCopy)
: TextEditor::DefaultAssistInterface(textDocument, position, editor->document()->filePath(),
reason)
, m_editor(editor)
, m_gotCppSpecifics(false)
, m_workingCopy(workingCopy)
{}
CppCompletionAssistInterface(QTextDocument *textDocument,
......@@ -206,6 +209,7 @@ private:
TextEditor::BaseTextEditor *m_editor;
mutable bool m_gotCppSpecifics;
CppModelManagerInterface::WorkingCopy m_workingCopy;
mutable CPlusPlus::Snapshot m_snapshot;
mutable QStringList m_includePaths;
mutable QStringList m_frameworkPaths;
......
......@@ -282,7 +282,8 @@ void CppEditorSupport::updateDocument()
m_updateDocumentTimer->start(m_updateDocumentInterval);
}
static void parse(QFutureInterface<void> &future, QSharedPointer<SnapshotUpdater> updater)
static void parse(QFutureInterface<void> &future, QSharedPointer<SnapshotUpdater> updater,
CppModelManagerInterface::WorkingCopy workingCopy)
{
future.setProgressRange(0, 1);
if (future.isCanceled()) {
......@@ -291,7 +292,7 @@ static void parse(QFutureInterface<void> &future, QSharedPointer<SnapshotUpdater
}
CppModelManager *cmm = qobject_cast<CppModelManager *>(CppModelManager::instance());
updater->update(cmm->workingCopy());
updater->update(workingCopy);
cmm->finishedRefreshingSourceFiles(QStringList(updater->fileInEditor()));
future.setProgressValue(1);
......@@ -310,7 +311,8 @@ void CppEditorSupport::updateDocumentNow()
if (m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo())
startHighlighting();
m_documentParser = QtConcurrent::run(&parse, snapshotUpdater());
m_documentParser = QtConcurrent::run(&parse, snapshotUpdater(),
CppModelManager::instance()->workingCopy());
}
}
......
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