mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-19 15:17:24 +02:00
Lock the attribute mapping, since it can be accessed from multiple threads.
This commit is contained in:
parent
efe443e2ff
commit
f9036dbaec
2 changed files with 16 additions and 1 deletions
|
@ -9,7 +9,9 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <QReadLocker>
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
|
#include <QWriteLocker>
|
||||||
|
|
||||||
#include "AttributeRegistry.h"
|
#include "AttributeRegistry.h"
|
||||||
#include "MetavoxelData.h"
|
#include "MetavoxelData.h"
|
||||||
|
@ -69,6 +71,7 @@ AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute
|
||||||
if (!attribute) {
|
if (!attribute) {
|
||||||
return attribute;
|
return attribute;
|
||||||
}
|
}
|
||||||
|
QWriteLocker locker(&_attributesLock);
|
||||||
AttributePointer& pointer = _attributes[attribute->getName()];
|
AttributePointer& pointer = _attributes[attribute->getName()];
|
||||||
if (!pointer) {
|
if (!pointer) {
|
||||||
pointer = attribute;
|
pointer = attribute;
|
||||||
|
@ -77,9 +80,15 @@ AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttributeRegistry::deregisterAttribute(const QString& name) {
|
void AttributeRegistry::deregisterAttribute(const QString& name) {
|
||||||
|
QWriteLocker locker(&_attributesLock);
|
||||||
_attributes.remove(name);
|
_attributes.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AttributePointer AttributeRegistry::getAttribute(const QString& name) {
|
||||||
|
QReadLocker locker(&_attributesLock);
|
||||||
|
return _attributes.value(name);
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue AttributeRegistry::getAttribute(QScriptContext* context, QScriptEngine* engine) {
|
QScriptValue AttributeRegistry::getAttribute(QScriptContext* context, QScriptEngine* engine) {
|
||||||
return engine->newQObject(getInstance()->getAttribute(context->argument(0).toString()).data(), QScriptEngine::QtOwnership,
|
return engine->newQObject(getInstance()->getAttribute(context->argument(0).toString()).data(), QScriptEngine::QtOwnership,
|
||||||
QScriptEngine::PreferExistingWrapperObject);
|
QScriptEngine::PreferExistingWrapperObject);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -61,11 +62,14 @@ public:
|
||||||
void deregisterAttribute(const QString& name);
|
void deregisterAttribute(const QString& name);
|
||||||
|
|
||||||
/// Retrieves an attribute by name.
|
/// Retrieves an attribute by name.
|
||||||
AttributePointer getAttribute(const QString& name) const { return _attributes.value(name); }
|
AttributePointer getAttribute(const QString& name);
|
||||||
|
|
||||||
/// Returns a reference to the attribute hash.
|
/// Returns a reference to the attribute hash.
|
||||||
const QHash<QString, AttributePointer>& getAttributes() const { return _attributes; }
|
const QHash<QString, AttributePointer>& getAttributes() const { return _attributes; }
|
||||||
|
|
||||||
|
/// Returns a reference to the attributes lock.
|
||||||
|
QReadWriteLock& getAttributesLock() { return _attributesLock; }
|
||||||
|
|
||||||
/// Returns a reference to the standard SharedObjectPointer "guide" attribute.
|
/// Returns a reference to the standard SharedObjectPointer "guide" attribute.
|
||||||
const AttributePointer& getGuideAttribute() const { return _guideAttribute; }
|
const AttributePointer& getGuideAttribute() const { return _guideAttribute; }
|
||||||
|
|
||||||
|
@ -92,6 +96,8 @@ private:
|
||||||
static QScriptValue getAttribute(QScriptContext* context, QScriptEngine* engine);
|
static QScriptValue getAttribute(QScriptContext* context, QScriptEngine* engine);
|
||||||
|
|
||||||
QHash<QString, AttributePointer> _attributes;
|
QHash<QString, AttributePointer> _attributes;
|
||||||
|
QReadWriteLock _attributesLock;
|
||||||
|
|
||||||
AttributePointer _guideAttribute;
|
AttributePointer _guideAttribute;
|
||||||
AttributePointer _spannersAttribute;
|
AttributePointer _spannersAttribute;
|
||||||
AttributePointer _colorAttribute;
|
AttributePointer _colorAttribute;
|
||||||
|
|
Loading…
Reference in a new issue