Skip to content

Commit

Permalink
fix data race: addFilter() and resizeMap() can be executed concurrent…
Browse files Browse the repository at this point in the history
…ly (#3518)

Co-authored-by: Dirk Braunschweiger <dirk.braunschweiger@symovo.de>
  • Loading branch information
2 people authored and SteveMacenski committed Jun 9, 2023
1 parent 0778686 commit 49e0756
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit 49e0756

Please sign in to comment.