Replaced mutex locking with lock guard

This commit is contained in:
ksuprynowicz 2023-10-31 18:37:05 +01:00
parent 7481130e61
commit 6645763117

View file

@ -2553,13 +2553,12 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer
}
entityDescription["DataVersion"] = _persistDataVersion;
entityDescription["Id"] = _persistID;
scriptEngineMutex.lock();
const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
RecurseOctreeToMapOperator theOperator(entityDescription, element, scriptEngine.get(), skipDefaultValues,
skipThoseWithBadParents, _myAvatar);
withReadLock([&] {
recurseTreeWithOperator(&theOperator);
});
scriptEngineMutex.unlock();
return true;
}
@ -2728,11 +2727,12 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
" mapped it to parentJointIndex " << entityMap["parentJointIndex"].toInt();
}
scriptEngineMutex.lock();
ScriptValue entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
EntityItemProperties properties;
EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);
scriptEngineMutex.unlock();
{
const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
ScriptValue entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);
}
EntityItemID entityItemID;
if (entityMap.contains("id")) {
@ -2881,12 +2881,11 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
}
bool EntityTree::writeToJSON(QString& jsonString, const OctreeElementPointer& element) {
scriptEngineMutex.lock();
const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
RecurseOctreeToJSONOperator theOperator(element, scriptEngine.get(), jsonString);
withReadLock([&] {
recurseTreeWithOperator(&theOperator);
});
scriptEngineMutex.unlock();
jsonString = theOperator.getJson();
return true;