Skip to content

Commit

Permalink
Added mutex to FindDynamicObjects and PropagateDynamicObjects to avoi…
Browse files Browse the repository at this point in the history
…d multiple threads using the same instances at the same time.
  • Loading branch information
robertosfield committed Jun 19, 2024
1 parent 826dfd0 commit 971e164
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/vsg/utils/FindDynamicObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace vsg
class VSG_DECLSPEC FindDynamicObjects : public Inherit<ConstVisitor, FindDynamicObjects>
{
public:

std::mutex mutex;
std::set<const Object*> dynamicObjects;

inline void tag(const Object* object)
Expand Down
1 change: 1 addition & 0 deletions include/vsg/utils/PropagateDynamicObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace vsg
public:
PropagateDynamicObjects();

std::mutex mutex;
std::set<const Object*> dynamicObjects;
std::stack<bool> taggedStack;

Expand Down
4 changes: 4 additions & 0 deletions src/vsg/io/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ ref_ptr<Object> vsg::read(const Path& filename, ref_ptr<const Options> 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<std::mutex> fdo_lock(options->findDynamicObjects->mutex);

options->findDynamicObjects->dynamicObjects.clear();
load->object->accept(*(options->findDynamicObjects));

std::scoped_lock<std::mutex> pdo_lock(options->propagateDynamicObjects->mutex);
options->propagateDynamicObjects->dynamicObjects.swap(options->findDynamicObjects->dynamicObjects);
load->object->accept(*(options->propagateDynamicObjects));

Expand Down

0 comments on commit 971e164

Please sign in to comment.