aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmldom/qqmldomtop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmldom/qqmldomtop.cpp')
-rw-r--r--src/qmldom/qqmldomtop.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/qmldom/qqmldomtop.cpp b/src/qmldom/qqmldomtop.cpp
index ed62310075..e0f88f67c1 100644
--- a/src/qmldom/qqmldomtop.cpp
+++ b/src/qmldom/qqmldomtop.cpp
@@ -49,7 +49,6 @@
#include <QtQml/private/qqmljsastvisitor_p.h>
#include <QtQml/private/qqmljsast_p.h>
-#include <QtCore/QAtomicInt>
#include <QtCore/QBasicMutex>
#include <QtCore/QCborArray>
#include <QtCore/QDebug>
@@ -158,11 +157,14 @@ DomUniverse::DomUniverse(QString universeName, Options options):
std::shared_ptr<DomUniverse> DomUniverse::guaranteeUniverse(std::shared_ptr<DomUniverse> univ)
{
- static QAtomicInt counter(0);
+ const auto next = [] {
+ static std::atomic<int> counter(0);
+ return counter.fetch_add(1, std::memory_order_relaxed) + 1;
+ };
if (univ)
return univ;
return std::shared_ptr<DomUniverse>(
- new DomUniverse(QLatin1String("universe") + QString::number(++counter)));
+ new DomUniverse(QLatin1String("universe") + QString::number(next())));
}
DomItem DomUniverse::create(QString universeName, Options options)
@@ -287,11 +289,14 @@ void DomUniverse::loadFile(DomItem &self, QString canonicalFilePath, QString log
case DomType::QmlFile:
case DomType::QmltypesFile:
case DomType::QmldirFile:
- case DomType::QmlDirectory:
+ case DomType::QmlDirectory: {
+ // Protect the queue from concurrent access.
+ QMutexLocker l(mutex());
m_queue.enqueue(ParsingTask { QDateTime::currentDateTime(), loadOptions, fType,
canonicalFilePath, logicalPath, code, codeDate,
self.ownerAs<DomUniverse>(), callback });
break;
+ }
default:
self.addError(myErrors()
.error(tr("Ignoring request to load file %1 of unexpected type %2, "
@@ -350,7 +355,14 @@ updateEntry(DomItem &univ, std::shared_ptr<T> newItem,
void DomUniverse::execQueue()
{
- ParsingTask t = m_queue.dequeue();
+ ParsingTask t;
+ {
+ // Protect the queue from concurrent access.
+ QMutexLocker l(mutex());
+ if (m_queue.isEmpty())
+ return;
+ t = m_queue.dequeue();
+ }
shared_ptr<DomUniverse> topPtr = t.requestingUniverse.lock();
if (!topPtr) {
myErrors().error(tr("Ignoring callback for loading of %1: universe is not valid anymore").arg(t.canonicalPath)).handle();