From 6ae43c40de8cc35af3b3ba401fa6504ff782cd86 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 10 Jan 2022 13:34:12 +0000 Subject: Fix thread safety issues in TimelineDecoder and associated unit tests Enforce serialized access to TimelineDecoder::m_Model by removing public access funtion and replacing with an 'Apply' method taking a lambda and uses a std::lock. Use the new lambda when invoking callbacks. Change-Id: I6ea2fbca990736f3be63e80897f175421f19f0c1 Signed-off-by: Matthew Bentham --- profiling/server/include/timelineDecoder/TimelineDecoder.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'profiling/server/include/timelineDecoder/TimelineDecoder.hpp') diff --git a/profiling/server/include/timelineDecoder/TimelineDecoder.hpp b/profiling/server/include/timelineDecoder/TimelineDecoder.hpp index ea4b144860..9776ec91f9 100644 --- a/profiling/server/include/timelineDecoder/TimelineDecoder.hpp +++ b/profiling/server/include/timelineDecoder/TimelineDecoder.hpp @@ -6,6 +6,8 @@ #include "ITimelineDecoder.hpp" +#include +#include #include namespace arm @@ -40,7 +42,11 @@ public: virtual TimelineStatus CreateLabel(const Label &) override; virtual TimelineStatus CreateRelationship(const Relationship &) override; - const Model& GetModel(); + template + decltype(auto) ApplyToModel(F&& f){ + std::lock_guard lock(m_ModelMutex); + return f(m_Model); + } TimelineStatus SetEntityCallback(const OnNewEntityCallback); TimelineStatus SetEventClassCallback(const OnNewEventClassCallback); @@ -54,6 +60,7 @@ public: private: Model m_Model; + std::mutex m_ModelMutex; OnNewEntityCallback m_OnNewEntityCallback; OnNewEventClassCallback m_OnNewEventClassCallback; @@ -69,4 +76,4 @@ private: }; } // namespace pipe -} // namespace arm \ No newline at end of file +} // namespace arm -- cgit v1.2.1