From b22ecba17983469d11cd39789a570c5938b9b4c0 Mon Sep 17 00:00:00 2001 From: Richard Brice <37087370+RickBrice@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:54:41 -0700 Subject: [PATCH] Implements mutually exclusive access to mapping cache with a mutex --- src/ifcgeom/mapping/mapping.cpp | 4 +++- src/ifcgeom/mapping/mapping.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ifcgeom/mapping/mapping.cpp b/src/ifcgeom/mapping/mapping.cpp index d9d140dc54..1fbd73d0c7 100644 --- a/src/ifcgeom/mapping/mapping.cpp +++ b/src/ifcgeom/mapping/mapping.cpp @@ -612,6 +612,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) { taxonomy::ptr mapping::map(const IfcBaseInterface* inst) { auto iden = inst->as()->identity(); if (use_caching_) { + std::lock_guard guard(cache_guard_); auto it = cache_.find(iden); if (it != cache_.end()) { return it->second; @@ -629,7 +630,8 @@ taxonomy::ptr mapping::map(const IfcBaseInterface* inst) { if (item) { if (use_caching_) { - cache_.insert({ iden, item }); + std::lock_guard guard(cache_guard_); + cache_.insert({iden, item}); } } else if (!matched) { Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst); diff --git a/src/ifcgeom/mapping/mapping.h b/src/ifcgeom/mapping/mapping.h index 1111101bb6..ace92a2276 100644 --- a/src/ifcgeom/mapping/mapping.h +++ b/src/ifcgeom/mapping/mapping.h @@ -6,6 +6,8 @@ #include "../../ifcparse/IfcFile.h" #include "../../ifcparse/IfcLogger.h" +#include + #define INCLUDE_SCHEMA(x) STRINGIFY(../../ifcparse/x.h) #include INCLUDE_SCHEMA(IfcSchema) #undef INCLUDE_SCHEMA @@ -24,6 +26,7 @@ namespace geometry { std::string length_unit_name_; std::map cache_; + std::mutex cache_guard_; // provides mutually exclusive access to cache_ const IfcParse::declaration* placement_rel_to_type_; const IfcUtil::IfcBaseEntity* placement_rel_to_instance_;