From 971e16413bd79bb74040563b167ee6009cd9106e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Jun 2024 12:13:33 +0100 Subject: [PATCH] Added mutex to FindDynamicObjects and PropagateDynamicObjects to avoid multiple threads using the same instances at the same time. --- include/vsg/utils/FindDynamicObjects.h | 2 ++ include/vsg/utils/PropagateDynamicObjects.h | 1 + src/vsg/io/read.cpp | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/include/vsg/utils/FindDynamicObjects.h b/include/vsg/utils/FindDynamicObjects.h index 1fc167451..2e1427256 100644 --- a/include/vsg/utils/FindDynamicObjects.h +++ b/include/vsg/utils/FindDynamicObjects.h @@ -24,6 +24,8 @@ namespace vsg class VSG_DECLSPEC FindDynamicObjects : public Inherit { public: + + std::mutex mutex; std::set dynamicObjects; inline void tag(const Object* object) diff --git a/include/vsg/utils/PropagateDynamicObjects.h b/include/vsg/utils/PropagateDynamicObjects.h index ccfde409a..4c60514f5 100644 --- a/include/vsg/utils/PropagateDynamicObjects.h +++ b/include/vsg/utils/PropagateDynamicObjects.h @@ -26,6 +26,7 @@ namespace vsg public: PropagateDynamicObjects(); + std::mutex mutex; std::set dynamicObjects; std::stack taggedStack; diff --git a/src/vsg/io/read.cpp b/src/vsg/io/read.cpp index dca5a789b..cf578387c 100644 --- a/src/vsg/io/read.cpp +++ b/src/vsg/io/read.cpp @@ -77,9 +77,13 @@ ref_ptr vsg::read(const Path& filename, ref_ptr options) if (load->object && options && options->findDynamicObjects && options->propagateDynamicObjects) { // invoke the find and propogate visitiors to collate all the dynamic objects that will need to be cloned. + + std::scoped_lock fdo_lock(options->findDynamicObjects->mutex); + options->findDynamicObjects->dynamicObjects.clear(); load->object->accept(*(options->findDynamicObjects)); + std::scoped_lock pdo_lock(options->propagateDynamicObjects->mutex); options->propagateDynamicObjects->dynamicObjects.swap(options->findDynamicObjects->dynamicObjects); load->object->accept(*(options->propagateDynamicObjects));