Browse Source

Don't write-lock Engine::fromJson() because it only needs it when adding modules and cables, which already has a write-lock.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
4e44157d27
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      src/engine/Engine.cpp

+ 5
- 5
src/engine/Engine.cpp View File

@@ -243,8 +243,7 @@ struct Engine::Internal {
Readers lock when using the engine's state. Readers lock when using the engine's state.
*/ */
ReadWriteMutex mutex; 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; std::mutex blockMutex;


@@ -1084,7 +1083,8 @@ json_t* Engine::toJson() {




void Engine::fromJson(json_t* rootJ) { 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(); clear();
// modules // modules
json_t* modulesJ = json_object_get(rootJ, "modules"); json_t* modulesJ = json_object_get(rootJ, "modules");
@@ -1105,7 +1105,7 @@ void Engine::fromJson(json_t* rootJ) {
module->id = moduleIndex; module->id = moduleIndex;
} }


// This method exclusively locks
// This write-locks
addModule(module); addModule(module);
} }
catch (Exception& e) { catch (Exception& e) {
@@ -1127,7 +1127,7 @@ void Engine::fromJson(json_t* rootJ) {
Cable* cable = new Cable; Cable* cable = new Cable;
try { try {
cable->fromJson(cableJ); cable->fromJson(cableJ);
// This method exclusively locks
// This write-locks
addCable(cable); addCable(cable);
} }
catch (Exception& e) { catch (Exception& e) {


Loading…
Cancel
Save