@@ -33,7 +33,7 @@ void Cable::fromJson(json_t* rootJ) { | |||||
if (!inputModuleIdJ) | if (!inputModuleIdJ) | ||||
throw Exception("Input module ID not found for cable %lld", (long long) id); | throw Exception("Input module ID not found for cable %lld", (long long) id); | ||||
int64_t inputModuleId = json_integer_value(inputModuleIdJ); | int64_t inputModuleId = json_integer_value(inputModuleIdJ); | ||||
inputModule = APP->engine->getModule(inputModuleId); | |||||
inputModule = APP->engine->getModule_NoLock(inputModuleId); | |||||
if (!inputModule) | if (!inputModule) | ||||
throw Exception("Input module %lld not found for cable %lld", (long long) inputModuleId, (long long) id); | throw Exception("Input module %lld not found for cable %lld", (long long) inputModuleId, (long long) id); | ||||
@@ -48,7 +48,7 @@ void Cable::fromJson(json_t* rootJ) { | |||||
if (!outputModuleIdJ) | if (!outputModuleIdJ) | ||||
throw Exception("Output module ID not found for cable %lld", (long long) id); | throw Exception("Output module ID not found for cable %lld", (long long) id); | ||||
int64_t outputModuleId = json_integer_value(outputModuleIdJ); | int64_t outputModuleId = json_integer_value(outputModuleIdJ); | ||||
outputModule = APP->engine->getModule(outputModuleId); | |||||
outputModule = APP->engine->getModule_NoLock(outputModuleId); | |||||
if (!outputModule) | if (!outputModule) | ||||
throw Exception("Output module %lld not found for cable %lld", (long long) outputModuleId, (long long) id); | throw Exception("Output module %lld not found for cable %lld", (long long) outputModuleId, (long long) id); | ||||
@@ -1201,10 +1201,9 @@ json_t* Engine::toJson() { | |||||
void Engine::fromJson(json_t* rootJ) { | void Engine::fromJson(json_t* rootJ) { | ||||
// Don't write-lock the entire method because most of it doesn't need it. | |||||
std::lock_guard<SharedMutex> lock(internal->mutex); | |||||
// Write-locks | |||||
clear(); | |||||
clear_NoLock(); | |||||
// modules | // modules | ||||
json_t* modulesJ = json_object_get(rootJ, "modules"); | json_t* modulesJ = json_object_get(rootJ, "modules"); | ||||
if (!modulesJ) | if (!modulesJ) | ||||
@@ -1237,8 +1236,7 @@ void Engine::fromJson(json_t* rootJ) { | |||||
module->id = moduleIndex; | module->id = moduleIndex; | ||||
} | } | ||||
// Write-locks | |||||
addModule(module); | |||||
addModule_NoLock(module); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
WARN("Cannot load module: %s", e.what()); | WARN("Cannot load module: %s", e.what()); | ||||
@@ -1269,8 +1267,7 @@ void Engine::fromJson(json_t* rootJ) { | |||||
cable->id = cableIndex; | cable->id = cableIndex; | ||||
} | } | ||||
// Write-locks | |||||
addCable(cable); | |||||
addCable_NoLock(cable); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
WARN("Cannot load cable: %s", e.what()); | WARN("Cannot load cable: %s", e.what()); | ||||
@@ -1284,7 +1281,7 @@ void Engine::fromJson(json_t* rootJ) { | |||||
json_t* masterModuleIdJ = json_object_get(rootJ, "masterModuleId"); | json_t* masterModuleIdJ = json_object_get(rootJ, "masterModuleId"); | ||||
if (masterModuleIdJ) { | if (masterModuleIdJ) { | ||||
Module* masterModule = getModule(json_integer_value(masterModuleIdJ)); | Module* masterModule = getModule(json_integer_value(masterModuleIdJ)); | ||||
setMasterModule(masterModule); | |||||
setMasterModule_NoLock(masterModule); | |||||
} | } | ||||
} | } | ||||