Skip to content

Commit

Permalink
Fix thread safety in environment.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Nov 16, 2023
1 parent cb053ec commit 1faf3e9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tesseract_environment/src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ bool Environment::init(const tesseract_scene_graph::SceneGraph& scene_graph,

bool Environment::init(const std::string& urdf_string, const tesseract_common::ResourceLocator::ConstPtr& locator)
{
resource_locator_ = locator;
{
std::unique_lock<std::shared_mutex> lock(mutex_);
resource_locator_ = locator;
}

// Parse urdf string into Scene Graph
tesseract_scene_graph::SceneGraph::Ptr scene_graph;
Expand All @@ -123,7 +126,10 @@ bool Environment::init(const std::string& urdf_string,
const std::string& srdf_string,
const tesseract_common::ResourceLocator::ConstPtr& locator)
{
resource_locator_ = locator;
{
std::unique_lock<std::shared_mutex> lock(mutex_);
resource_locator_ = locator;
}

// Parse urdf string into Scene Graph
tesseract_scene_graph::SceneGraph::Ptr scene_graph;
Expand Down Expand Up @@ -158,7 +164,10 @@ bool Environment::init(const std::string& urdf_string,
bool Environment::init(const tesseract_common::fs::path& urdf_path,
const tesseract_common::ResourceLocator::ConstPtr& locator)
{
resource_locator_ = locator;
{
std::unique_lock<std::shared_mutex> lock(mutex_);
resource_locator_ = locator;
}

// Parse urdf file into Scene Graph
tesseract_scene_graph::SceneGraph::Ptr scene_graph;
Expand All @@ -181,7 +190,10 @@ bool Environment::init(const tesseract_common::fs::path& urdf_path,
const tesseract_common::fs::path& srdf_path,
const tesseract_common::ResourceLocator::ConstPtr& locator)
{
resource_locator_ = locator;
{
std::unique_lock<std::shared_mutex> lock(mutex_);
resource_locator_ = locator;
}

// Parse urdf file into Scene Graph
tesseract_scene_graph::SceneGraph::Ptr scene_graph;
Expand Down

0 comments on commit 1faf3e9

Please sign in to comment.