forked from qt-creator/qt-creator
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: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -182,17 +182,6 @@ QmlObjectValue::QmlObjectValue(FakeMetaObject::ConstPtr metaObject, const QStrin
|
|||||||
QmlObjectValue::~QmlObjectValue()
|
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
|
void QmlObjectValue::processMembers(MemberProcessor *processor) const
|
||||||
{
|
{
|
||||||
// process the meta enums
|
// process the meta enums
|
||||||
@@ -207,6 +196,19 @@ void QmlObjectValue::processMembers(MemberProcessor *processor) const
|
|||||||
// all explicitly defined signal names
|
// all explicitly defined signal names
|
||||||
QSet<QString> explicitSignals;
|
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
|
// process the meta methods
|
||||||
for (int index = 0; index < _metaObject->methodCount(); ++index) {
|
for (int index = 0; index < _metaObject->methodCount(); ++index) {
|
||||||
const FakeMetaMethod method = _metaObject->method(index);
|
const FakeMetaMethod method = _metaObject->method(index);
|
||||||
@@ -214,7 +216,7 @@ void QmlObjectValue::processMembers(MemberProcessor *processor) const
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString methodName;
|
QString methodName;
|
||||||
const Value *signature = findOrCreateSignature(index, method, &methodName);
|
const Value *signature = signatures->at(index);
|
||||||
|
|
||||||
if (method.methodType() == FakeMetaMethod::Slot && method.access() == FakeMetaMethod::Public) {
|
if (method.methodType() == FakeMetaMethod::Slot && method.access() == FakeMetaMethod::Public) {
|
||||||
processor->processSlot(methodName, signature);
|
processor->processSlot(methodName, signature);
|
||||||
|
@@ -449,8 +449,6 @@ public:
|
|||||||
LanguageUtils::FakeMetaEnum getEnum(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
|
LanguageUtils::FakeMetaEnum getEnum(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
|
||||||
const QmlEnumValue *getEnumValue(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
|
const QmlEnumValue *getEnumValue(const QString &typeName, const QmlObjectValue **foundInScope = 0) const;
|
||||||
protected:
|
protected:
|
||||||
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
|
|
||||||
QString *methodName) const;
|
|
||||||
bool isDerivedFrom(LanguageUtils::FakeMetaObject::ConstPtr base) const;
|
bool isDerivedFrom(LanguageUtils::FakeMetaObject::ConstPtr base) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -462,7 +460,7 @@ private:
|
|||||||
// needed in cases when B 1.0 has A 1.1 as prototype when imported as 1.1
|
// 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 _componentVersion;
|
||||||
const LanguageUtils::ComponentVersion _importVersion;
|
const LanguageUtils::ComponentVersion _importVersion;
|
||||||
mutable QHash<int, const Value *> _metaSignature;
|
mutable QAtomicPointer< QList<const Value *> > _metaSignatures;
|
||||||
QHash<QString, const QmlEnumValue * > _enums;
|
QHash<QString, const QmlEnumValue * > _enums;
|
||||||
int _metaObjectRevision;
|
int _metaObjectRevision;
|
||||||
};
|
};
|
||||||
|
@@ -453,6 +453,7 @@ const ObjectValue *ValueOwner::qtObject() const
|
|||||||
|
|
||||||
void ValueOwner::registerValue(Value *value)
|
void ValueOwner::registerValue(Value *value)
|
||||||
{
|
{
|
||||||
|
// ### get rid of this lock
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
_registeredValues.append(value);
|
_registeredValues.append(value);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user