Skip to content

Commit

Permalink
Fix potential deadlock in ResourceManager
Browse files Browse the repository at this point in the history
  • Loading branch information
cwecht authored and destogl committed Feb 14, 2023
1 parent 1c058d7 commit f1a258f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,7 @@ void ResourceManager::load_urdf(const std::string & urdf, bool validate_interfac
{
if (individual_hardware_info.type == actuator_type)
{
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
std::scoped_lock guard(resource_interfaces_lock_, claimed_command_interfaces_lock_);
resource_storage_->load_and_initialize_actuator(individual_hardware_info);
}
if (individual_hardware_info.type == sensor_type)
Expand All @@ -613,8 +612,7 @@ void ResourceManager::load_urdf(const std::string & urdf, bool validate_interfac
}
if (individual_hardware_info.type == system_type)
{
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
std::scoped_lock guard(resource_interfaces_lock_, claimed_command_interfaces_lock_);
resource_storage_->load_and_initialize_system(individual_hardware_info);
}
}
Expand Down Expand Up @@ -676,8 +674,7 @@ bool ResourceManager::state_interface_is_available(const std::string & name) con
void ResourceManager::import_controller_reference_interfaces(
const std::string & controller_name, std::vector<CommandInterface> & interfaces)
{
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
std::scoped_lock guard(resource_interfaces_lock_, claimed_command_interfaces_lock_);
auto interface_names = resource_storage_->add_command_interfaces(interfaces);
resource_storage_->controllers_reference_interfaces_map_[controller_name] = interface_names;
}
Expand Down Expand Up @@ -731,8 +728,7 @@ void ResourceManager::remove_controller_reference_interfaces(const std::string &
resource_storage_->controllers_reference_interfaces_map_.at(controller_name);
resource_storage_->controllers_reference_interfaces_map_.erase(controller_name);

std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
std::scoped_lock guard(resource_interfaces_lock_, claimed_command_interfaces_lock_);
resource_storage_->remove_command_interfaces(interface_names);
}

Expand Down

0 comments on commit f1a258f

Please sign in to comment.