Add more thread safety to ModelManagerInterface

Add ModelManagerInterface *ModelManagerInterface::instanceForFuture()
method. If the returned instance is not null, it's guaranteed
that it will be valid at least as long as the passed QFuture object
isn't finished.

Use instanceForFuture() in Link c'tor, as it's called from
non-gui thread.

Change-Id: I7e5ee6ad27e8f71cc0cef7fd9a91b710e2f8f662
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
This commit is contained in:
Jarek Kobus
2021-06-21 13:51:55 +02:00
parent 54f3232f63
commit ca09774181
3 changed files with 21 additions and 3 deletions

View File

@@ -150,7 +150,9 @@ Link::Link(const Snapshot &snapshot, const ViewerContext &vContext, const Librar
d->diagnosticMessages = nullptr;
d->allDiagnosticMessages = nullptr;
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
QFutureInterface<void> fi;
fi.reportStarted();
ModelManagerInterface *modelManager = ModelManagerInterface::instanceForFuture(fi.future());
if (modelManager) {
const ModelManagerInterface::CppDataHash cppDataHash = modelManager->cppData();
{
@@ -176,6 +178,7 @@ Link::Link(const Snapshot &snapshot, const ViewerContext &vContext, const Librar
}
d->m_valueOwner->cppQmlTypes().setCppContextProperties(cppContextProperties);
}
fi.reportFinished();
}
ContextPtr Link::operator()(QHash<QString, QList<DiagnosticMessage> > *messages)