Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data race: addFilter() and resizeMap() can be executed concurrently #3518

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions nav2_costmap_2d/include/nav2_costmap_2d/layered_costmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ class LayeredCostmap
/**
* @brief Add a new costmap filter plugin to the filters vector to process
*/
void addFilter(std::shared_ptr<Layer> filter)
{
filters_.push_back(filter);
}
void addFilter(std::shared_ptr<Layer> filter);


/**
* @brief Get if the size of the costmap is locked
Expand Down
6 changes: 6 additions & 0 deletions nav2_costmap_2d/src/layered_costmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ void LayeredCostmap::addPlugin(std::shared_ptr<Layer> plugin)
plugins_.push_back(plugin);
}

void LayeredCostmap::addFilter(std::shared_ptr<Layer> filter)
{
std::unique_lock<Costmap2D::mutex_t> lock(*(combined_costmap_.getMutex()));
filters_.push_back(filter);
}

void LayeredCostmap::resizeMap(
unsigned int size_x, unsigned int size_y, double resolution,
double origin_x,
Expand Down