make getJSONParameters thread-safe

This commit is contained in:
Stephen Birarda 2017-01-18 17:43:57 -08:00
parent 916a7325bc
commit 33cde412b1
4 changed files with 11 additions and 4 deletions

View file

@ -246,6 +246,7 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const
if (entity && entity->shouldPreloadServerScript() && _entitiesScriptEngine) {
QString scriptUrl = entity->getServerScripts();
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
qDebug() << "Loading entity server script" << scriptUrl << "for" << entityID;
ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
entity->serverScriptHasPreloaded();
}

View file

@ -2246,7 +2246,7 @@ bool EntityItem::matchesJSONFilters(const QJsonObject& jsonFilters) const {
static const QString SERVER_SCRIPTS_PROPERTY = "serverScripts";
for (auto& property : jsonFilters.keys()) {
foreach(const auto& property, jsonFilters.keys()) {
if (property == SERVER_SCRIPTS_PROPERTY && jsonFilters[property] == EntityQueryFilterSymbol::NonDefault) {
// check if this entity has a non-default value for serverScripts
if (_serverScripts != ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS) {

View file

@ -132,7 +132,10 @@ int OctreeQuery::parseData(ReceivedMessage& message) {
sourceBuffer += binaryParametersBytes;
// grab the parameter object from the packed binary representation of JSON
_jsonParameters = QJsonDocument::fromBinaryData(binaryJSONParameters).object();
auto newJsonDocument = QJsonDocument::fromBinaryData(binaryJSONParameters);
QWriteLocker jsonParameterLocker { &_jsonParametersLock };
_jsonParameters = newJsonDocument.object();
}
return sourceBuffer - startPosition;

View file

@ -32,6 +32,7 @@ typedef unsigned long long quint64;
#include <glm/gtc/quaternion.hpp>
#include <QtCore/QJsonObject>
#include <QtCore/QReadWriteLock>
#include <NodeData.h>
@ -69,8 +70,9 @@ public:
void setCameraCenterRadius(float radius) { _cameraCenterRadius = radius; }
// getters/setters for JSON filter
QJsonObject getJSONParameters() { return _jsonParameters; }
void setJSONParameters(const QJsonObject& jsonParameters) { _jsonParameters = jsonParameters; }
QJsonObject getJSONParameters() { QReadLocker locker { &_jsonParametersLock }; return _jsonParameters; }
void setJSONParameters(const QJsonObject& jsonParameters)
{ QWriteLocker locker { &_jsonParametersLock }; _jsonParameters = jsonParameters; }
// related to Octree Sending strategies
int getMaxQueryPacketsPerSecond() const { return _maxQueryPPS; }
@ -104,6 +106,7 @@ protected:
uint8_t _usesFrustum = true;
QJsonObject _jsonParameters;
QReadWriteLock _jsonParametersLock;
private:
// privatize the copy constructor and assignment operator so they cannot be called