From 4e44157d277b98ccbefeece89d9c9c19279d4ba1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 9 Jan 2021 06:16:19 -0500 Subject: [PATCH] Don't write-lock Engine::fromJson() because it only needs it when adding modules and cables, which already has a write-lock. --- src/engine/Engine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 0e9afc69..9ab67daf 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -243,8 +243,7 @@ struct Engine::Internal { Readers lock when using the engine's state. */ ReadWriteMutex mutex; - /** Mutex that guards the block. - stepBlock() locks to guarantee its exclusivity. + /** Mutex that guards stepBlock() so it's not called simultaneously. */ std::mutex blockMutex; @@ -1084,7 +1083,8 @@ json_t* Engine::toJson() { void Engine::fromJson(json_t* rootJ) { - WriteLock lock(internal->mutex); + // Don't write-lock here because most of this function doesn't need it. + clear(); // modules json_t* modulesJ = json_object_get(rootJ, "modules"); @@ -1105,7 +1105,7 @@ void Engine::fromJson(json_t* rootJ) { module->id = moduleIndex; } - // This method exclusively locks + // This write-locks addModule(module); } catch (Exception& e) { @@ -1127,7 +1127,7 @@ void Engine::fromJson(json_t* rootJ) { Cable* cable = new Cable; try { cable->fromJson(cableJ); - // This method exclusively locks + // This write-locks addCable(cable); } catch (Exception& e) {