Implements mutually exclusive access to mapping cache with a mutex

This commit is contained in:
Richard Brice
2024-07-31 15:54:41 -07:00
parent 3c4a865e0b
commit b22ecba179
2 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -612,6 +612,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
taxonomy::ptr mapping::map(const IfcBaseInterface* inst) {
auto iden = inst->as<IfcUtil::IfcBaseClass>()->identity();
if (use_caching_) {
std::lock_guard<std::mutex> 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<std::mutex> guard(cache_guard_);
cache_.insert({iden, item});
}
} else if (!matched) {
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst);
+3
View File
@@ -6,6 +6,8 @@
#include "../../ifcparse/IfcFile.h"
#include "../../ifcparse/IfcLogger.h"
#include <mutex>
#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<uint32_t, ifcopenshell::geometry::taxonomy::ptr> 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_;