Skip to content

Commit 21d8df6

Browse files
easylyouKai-Tao Xie
andauthored
fix data race: addPlugin() and resizeMap() can be executed concurrently (#2512)
Co-authored-by: Kai-Tao Xie <kaitaoxie@qq.com>
1 parent e8d0005 commit 21d8df6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎nav2_costmap_2d/include/nav2_costmap_2d/layered_costmap.hpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ class LayeredCostmap
146146
/**
147147
* @brief Add a new plugin to the plugins vector to process
148148
*/
149-
void addPlugin(std::shared_ptr<Layer> plugin)
150-
{
151-
plugins_.push_back(plugin);
152-
}
149+
void addPlugin(std::shared_ptr<Layer> plugin);
150+
153151

154152
/**
155153
* @brief Add a new costmap filter plugin to the filters vector to process

‎nav2_costmap_2d/src/layered_costmap.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ LayeredCostmap::~LayeredCostmap()
8989
}
9090
}
9191

92+
void LayeredCostmap::addPlugin(std::shared_ptr<Layer> plugin)
93+
{
94+
std::unique_lock<Costmap2D::mutex_t> lock(*(combined_costmap_.getMutex()));
95+
plugins_.push_back(plugin);
96+
}
97+
9298
void LayeredCostmap::resizeMap(
9399
unsigned int size_x, unsigned int size_y, double resolution,
94100
double origin_x,

0 commit comments

Comments
 (0)