From 122302a6c71e3c2cd74cecd5b72928035a9596e0 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Fri, 16 Jul 2021 09:07:26 +0200 Subject: [PATCH] Add mutex to wm::CoreSegment --- .../armem/core/workingmemory/CoreSegment.cpp | 16 ++++++++++++++++ .../armem/core/workingmemory/CoreSegment.h | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp index 285235b76..47f361a42 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp @@ -8,6 +8,14 @@ namespace armarx::armem::wm { + CoreSegment::CoreSegment(const CoreSegment& other) : + CoreSegment::Base(other), + _mutex() + { + // Do not copy _mutex. + } + + Commit CoreSegment::toCommit() const { Commit c; @@ -18,6 +26,7 @@ namespace armarx::armem::wm return c; } + void CoreSegment::_copySelfWithoutData(CoreSegment& other) const { other.id() = _id; @@ -27,4 +36,11 @@ namespace armarx::armem::wm other.addProviderSegment(s.copyWithoutData()); } } + + + std::mutex& CoreSegment::mutex() const + { + return _mutex; + } + } diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h index 7847bbb71..ef4d5f36d 100644 --- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h @@ -1,5 +1,7 @@ #pragma once +#include <mutex> + #include "../base/CoreSegmentBase.h" #include "ProviderSegment.h" @@ -22,7 +24,7 @@ namespace armarx::armem::wm using Base::CoreSegmentBase; - CoreSegment(const CoreSegment& other) = default; + CoreSegment(const CoreSegment& other); CoreSegment(CoreSegment&& other) = default; CoreSegment& operator=(const CoreSegment& other) = default; CoreSegment& operator=(CoreSegment&& other) = default; @@ -33,10 +35,15 @@ namespace armarx::armem::wm */ Commit toCommit() const; + std::mutex& mutex() const; + + protected: virtual void _copySelfWithoutData(CoreSegment& other) const override; + mutable std::mutex _mutex; + }; } -- GitLab