From 9cef9c498437d225eebd1d90e16ca2b1b2089432 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Fri, 16 Jul 2021 11:08:32 +0200
Subject: [PATCH] Lock core segments in MemoryRemoteGui

---
 .../armem/server/ExampleMemory/ExampleMemory.cpp          | 2 +-
 .../RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp   | 8 +++-----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp
index 3ed4b4612..e007e8f5e 100644
--- a/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp
+++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp
@@ -122,7 +122,7 @@ namespace armarx
         using namespace armarx::RemoteGui::Client;
 
         {
-            std::scoped_lock lock(workingMemoryMutex);
+            // Core segments are locked by MemoryRemoteGui.
             tab.memoryGroup = armem::server::MemoryRemoteGui().makeGroupBox(workingMemory);
         }
 
diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp
index 9ab34efd9..9347cb7e9 100644
--- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp
+++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp
@@ -31,9 +31,10 @@ namespace armarx::armem::server
     }
 
 
-
     MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::CoreSegment& coreSegment) const
     {
+        std::scoped_lock lock(coreSegment.mutex());
+
         GroupBox group;
         group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.providerSegments().size()));
 
@@ -50,7 +51,6 @@ namespace armarx::armem::server
     }
 
 
-
     MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::ProviderSegment& providerSegment) const
     {
         GroupBox group;
@@ -69,7 +69,6 @@ namespace armarx::armem::server
     }
 
 
-
     MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::Entity& entity) const
     {
         GroupBox group;
@@ -109,7 +108,6 @@ namespace armarx::armem::server
     }
 
 
-
     MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::EntitySnapshot& snapshot) const
     {
         GroupBox group;
@@ -129,6 +127,7 @@ namespace armarx::armem::server
         return group;
     }
 
+
     MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::EntityInstance& instance) const
     {
         GroupBox group;
@@ -153,7 +152,6 @@ namespace armarx::armem::server
     }
 
 
-
     std::string MemoryRemoteGui::makeGroupLabel(
         const std::string& term, const std::string& name, size_t size,
         const std::string& namePrefix, const std::string& nameSuffix) const
-- 
GitLab