File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 40
40
41
41
#include < map>
42
42
#include < vector>
43
+ #include < mutex>
43
44
44
45
#include " rclcpp/rclcpp.hpp"
45
46
#include " nav2_costmap_2d/layer.hpp"
@@ -77,7 +78,7 @@ class InflationLayer : public Layer
77
78
public:
78
79
InflationLayer ();
79
80
80
- ~InflationLayer () override = default ;
81
+ ~InflationLayer ();
81
82
82
83
void onInitialize () override ;
83
84
void updateBounds (
@@ -115,6 +116,13 @@ class InflationLayer : public Layer
115
116
return cost;
116
117
}
117
118
119
+ // Provide a typedef to ease future code maintenance
120
+ typedef std::recursive_mutex mutex_t ;
121
+ mutex_t * getMutex ()
122
+ {
123
+ return access_;
124
+ }
125
+
118
126
protected:
119
127
void onFootprintChanged () override ;
120
128
@@ -184,6 +192,7 @@ class InflationLayer : public Layer
184
192
185
193
// Indicates that the entire costmap should be reinflated next time around.
186
194
bool need_reinflation_;
195
+ mutex_t * access_;
187
196
};
188
197
189
198
} // namespace nav2_costmap_2d
Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ InflationLayer::InflationLayer()
71
71
last_max_x_(std::numeric_limits<double >::max()),
72
72
last_max_y_(std::numeric_limits<double >::max())
73
73
{
74
+ access_ = new mutex_t ();
75
+ }
76
+
77
+ InflationLayer::~InflationLayer ()
78
+ {
79
+ delete access_;
74
80
}
75
81
76
82
void
@@ -160,6 +166,7 @@ InflationLayer::updateCosts(
160
166
int max_i,
161
167
int max_j)
162
168
{
169
+ std::lock_guard<Costmap2D::mutex_t > guard (*getMutex ());
163
170
if (!enabled_ || (cell_inflation_radius_ == 0 )) {
164
171
return ;
165
172
}
@@ -305,6 +312,7 @@ InflationLayer::enqueue(
305
312
void
306
313
InflationLayer::computeCaches ()
307
314
{
315
+ std::lock_guard<Costmap2D::mutex_t > guard (*getMutex ());
308
316
if (cell_inflation_radius_ == 0 ) {
309
317
return ;
310
318
}
You can’t perform that action at this time.
0 commit comments