Commit c7d8462b authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Fix threading issue in QmlObjectValue.

Still need to get rid of the lock in ValueOwner::registerValue.

Change-Id: If9bbc548de54edf52805906aaaf730f5c66573dd
Reviewed-on: http://codereview.qt-project.org/5542

Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 5daf6705
......@@ -182,17 +182,6 @@ QmlObjectValue::QmlObjectValue(FakeMetaObject::ConstPtr metaObject, const QStrin
QmlObjectValue::~QmlObjectValue()
{}
const Value *QmlObjectValue::findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const
{
*methodName = method.methodName();
const Value *value = _metaSignature.value(index);
if (! value) {
value = new MetaFunction(method, valueOwner());
_metaSignature.insert(index, value);
}
return value;
}
void QmlObjectValue::processMembers(MemberProcessor *processor) const
{
// process the meta enums
......@@ -207,6 +196,19 @@ void QmlObjectValue::processMembers(MemberProcessor *processor) const
// all explicitly defined signal names
QSet<QString> explicitSignals;
// make MetaFunction instances lazily when first needed
QList<const Value *> *signatures = _metaSignatures;
if (!signatures) {
signatures = new QList<const Value *>;
signatures->reserve(_metaObject->methodCount());
for (int index = 0; index < _metaObject->methodCount(); ++index)
signatures->append(new MetaFunction(_metaObject->method(index), valueOwner()));
if (!_metaSignatures.testAndSetOrdered(0, signatures)) {
delete signatures;
signatures = _metaSignatures;
}
}
// process the meta methods
for (int index = 0; index < _metaObject->methodCount(); ++index) {
const FakeMetaMethod method = _metaObject->method(index);
......@@ -214,7 +216,7 @@ void QmlObjectValue::processMembers(MemberProcessor *processor) const
continue;
QString methodName;
const Value *signature = findOrCreateSignature(index, method, &methodName);
const Value *signature = signatures->at(index);
if (method.methodType() == FakeMetaMethod::Slot && method.access() == FakeMetaMethod::Public) {
processor->processSlot(methodName, signature);
......
......@@ -449,8 +449,6 @@ public:
LanguageUtils::FakeMetaEnum getEnum(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
const QmlEnumValue *getEnumValue(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
protected:
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
QString *methodName) const;
bool isDerivedFrom(LanguageUtils::FakeMetaObject::ConstPtr base) const;
private:
......@@ -462,7 +460,7 @@ private:
// needed in cases when B 1.0 has A 1.1 as prototype when imported as 1.1
const LanguageUtils::ComponentVersion _componentVersion;
const LanguageUtils::ComponentVersion _importVersion;
mutable QHash<int, const Value *> _metaSignature;
mutable QAtomicPointer< QList<const Value *> > _metaSignatures;
QHash<QString, const QmlEnumValue * > _enums;
int _metaObjectRevision;
};
......
......@@ -453,6 +453,7 @@ const ObjectValue *ValueOwner::qtObject() const
void ValueOwner::registerValue(Value *value)
{
// ### get rid of this lock
QMutexLocker locker(&_mutex);
_registeredValues.append(value);
}
......
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