Skip to content

Commit

Permalink
Add resources_lock_ lock_guards to avoid race condition when loading …
Browse files Browse the repository at this point in the history
…robot_description through topic (backport ros-controls#1451) (ros-controls#1599)

* Add resources_lock_ lock_guards to avoid race condition when loading robot_description through topic (ros-controls#1451)

(cherry picked from commit 25f2c97)

# Conflicts:
#	hardware_interface/src/resource_manager.cpp

* Try fixing conflict.

---------

Co-authored-by: Sai Kishor Kothakota <[email protected]>
Co-authored-by: Dr. Denis <[email protected]>
Co-authored-by: Christoph Fröhlich <[email protected]>
  • Loading branch information
4 people authored Oct 13, 2024
1 parent cd55739 commit 847e655
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ void ResourceManager::load_urdf(

const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);
if (load_and_initialize_components)
std::lock_guard<std::recursive_mutex> resource_guard(resources_lock_);
{
for (const auto & individual_hardware_info : hardware_info)
{
Expand Down Expand Up @@ -1209,6 +1210,7 @@ return_type ResourceManager::set_component_state(
return false;
};

std::lock_guard<std::recursive_mutex> guard(resources_lock_);
bool found = find_set_component_state(
std::bind(&ResourceStorage::set_component_state<Actuator>, resource_storage_.get(), _1, _2),
resource_storage_->actuators_);
Expand Down

0 comments on commit 847e655

Please sign in to comment.