Skip to content

Commit a5abc74

Browse files
authored
fix(compare_map_segmentation): add missing mutex lock (#9097)
* fix(compare_map_segmentation): missing mutux Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * chore: rename mutex_ Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: remove unnecessary mutex Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: typos Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * chore: minimize mutex scope Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * chore: change to lock_guard Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: check tree initialization Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: memory ordering Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: replace all static_map_loader_mutex_ Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> --------- Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
1 parent 4061041 commit a5abc74

File tree

9 files changed

+53
-58
lines changed

9 files changed

+53
-58
lines changed

perception/autoware_compare_map_segmentation/src/distance_based_compare_map_filter/node.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ void DistanceBasedStaticMapLoader::onMapCallback(
3232
pcl::PointCloud<pcl::PointXYZ> map_pcl;
3333
pcl::fromROSMsg<pcl::PointXYZ>(*map, map_pcl);
3434
const auto map_pcl_ptr = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>(map_pcl);
35-
36-
(*mutex_ptr_).lock();
3735
map_ptr_ = map_pcl_ptr;
3836
*tf_map_input_frame_ = map_ptr_->header.frame_id;
3937
if (!tree_) {
@@ -44,13 +42,15 @@ void DistanceBasedStaticMapLoader::onMapCallback(
4442
}
4543
}
4644
tree_->setInputCloud(map_ptr_);
47-
48-
(*mutex_ptr_).unlock();
45+
is_initialized_.store(true, std::memory_order_release);
4946
}
5047

5148
bool DistanceBasedStaticMapLoader::is_close_to_map(
5249
const pcl::PointXYZ & point, const double distance_threshold)
5350
{
51+
if (!is_initialized_.load(std::memory_order_acquire)) {
52+
return false;
53+
}
5454
if (map_ptr_ == NULL) {
5555
return false;
5656
}
@@ -126,10 +126,10 @@ DistanceBasedCompareMapFilterComponent::DistanceBasedCompareMapFilterComponent(
126126
rclcpp::CallbackGroup::SharedPtr main_callback_group;
127127
main_callback_group = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
128128
distance_based_map_loader_ = std::make_unique<DistanceBasedDynamicMapLoader>(
129-
this, distance_threshold_, &tf_input_frame_, &mutex_, main_callback_group);
129+
this, distance_threshold_, &tf_input_frame_, main_callback_group);
130130
} else {
131-
distance_based_map_loader_ = std::make_unique<DistanceBasedStaticMapLoader>(
132-
this, distance_threshold_, &tf_input_frame_, &mutex_);
131+
distance_based_map_loader_ =
132+
std::make_unique<DistanceBasedStaticMapLoader>(this, distance_threshold_, &tf_input_frame_);
133133
}
134134
}
135135

perception/autoware_compare_map_segmentation/src/distance_based_compare_map_filter/node.hpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class DistanceBasedStaticMapLoader : public VoxelGridStaticMapLoader
4141

4242
public:
4343
DistanceBasedStaticMapLoader(
44-
rclcpp::Node * node, double leaf_size, std::string * tf_map_input_frame, std::mutex * mutex)
45-
: VoxelGridStaticMapLoader(node, leaf_size, 1.0, tf_map_input_frame, mutex)
44+
rclcpp::Node * node, double leaf_size, std::string * tf_map_input_frame)
45+
: VoxelGridStaticMapLoader(node, leaf_size, 1.0, tf_map_input_frame)
4646
{
4747
RCLCPP_INFO(logger_, "DistanceBasedStaticMapLoader initialized.\n");
4848
}
@@ -55,9 +55,9 @@ class DistanceBasedDynamicMapLoader : public VoxelGridDynamicMapLoader
5555
{
5656
public:
5757
DistanceBasedDynamicMapLoader(
58-
rclcpp::Node * node, double leaf_size, std::string * tf_map_input_frame, std::mutex * mutex,
58+
rclcpp::Node * node, double leaf_size, std::string * tf_map_input_frame,
5959
rclcpp::CallbackGroup::SharedPtr main_callback_group)
60-
: VoxelGridDynamicMapLoader(node, leaf_size, 1.0, tf_map_input_frame, mutex, main_callback_group)
60+
: VoxelGridDynamicMapLoader(node, leaf_size, 1.0, tf_map_input_frame, main_callback_group)
6161
{
6262
RCLCPP_INFO(logger_, "DistanceBasedDynamicMapLoader initialized.\n");
6363
}
@@ -94,9 +94,8 @@ class DistanceBasedDynamicMapLoader : public VoxelGridDynamicMapLoader
9494
current_voxel_grid_list_item.map_cell_kdtree = tree_tmp;
9595

9696
// add
97-
(*mutex_ptr_).lock();
97+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
9898
current_voxel_grid_dict_.insert({map_cell_to_add.cell_id, current_voxel_grid_list_item});
99-
(*mutex_ptr_).unlock();
10099
}
101100
};
102101

perception/autoware_compare_map_segmentation/src/voxel_based_approximate_compare_map_filter/node.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ VoxelBasedApproximateCompareMapFilterComponent::VoxelBasedApproximateCompareMapF
9595
rclcpp::CallbackGroup::SharedPtr main_callback_group;
9696
main_callback_group = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
9797
voxel_based_approximate_map_loader_ = std::make_unique<VoxelBasedApproximateDynamicMapLoader>(
98-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_,
99-
main_callback_group);
98+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, main_callback_group);
10099
} else {
101100
voxel_based_approximate_map_loader_ = std::make_unique<VoxelBasedApproximateStaticMapLoader>(
102-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_);
101+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_);
103102
}
104103
}
105104

perception/autoware_compare_map_segmentation/src/voxel_based_approximate_compare_map_filter/node.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class VoxelBasedApproximateStaticMapLoader : public VoxelGridStaticMapLoader
3333
public:
3434
explicit VoxelBasedApproximateStaticMapLoader(
3535
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
36-
std::string * tf_map_input_frame, std::mutex * mutex)
37-
: VoxelGridStaticMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex)
36+
std::string * tf_map_input_frame)
37+
: VoxelGridStaticMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame)
3838
{
3939
RCLCPP_INFO(logger_, "VoxelBasedApproximateStaticMapLoader initialized.\n");
4040
}
@@ -46,10 +46,9 @@ class VoxelBasedApproximateDynamicMapLoader : public VoxelGridDynamicMapLoader
4646
public:
4747
VoxelBasedApproximateDynamicMapLoader(
4848
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
49-
std::string * tf_map_input_frame, std::mutex * mutex,
50-
rclcpp::CallbackGroup::SharedPtr main_callback_group)
49+
std::string * tf_map_input_frame, rclcpp::CallbackGroup::SharedPtr main_callback_group)
5150
: VoxelGridDynamicMapLoader(
52-
node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex, main_callback_group)
51+
node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, main_callback_group)
5352
{
5453
RCLCPP_INFO(logger_, "VoxelBasedApproximateDynamicMapLoader initialized.\n");
5554
}

perception/autoware_compare_map_segmentation/src/voxel_based_compare_map_filter/node.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ VoxelBasedCompareMapFilterComponent::VoxelBasedCompareMapFilterComponent(
5454
rclcpp::CallbackGroup::SharedPtr main_callback_group;
5555
main_callback_group = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
5656
voxel_grid_map_loader_ = std::make_unique<VoxelGridDynamicMapLoader>(
57-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_,
58-
main_callback_group);
57+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, main_callback_group);
5958
} else {
6059
voxel_grid_map_loader_ = std::make_unique<VoxelGridStaticMapLoader>(
61-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_);
60+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_);
6261
}
6362
tf_input_frame_ = *(voxel_grid_map_loader_->tf_map_input_frame_);
6463
RCLCPP_INFO(this->get_logger(), "tf_map_input_frame: %s", tf_input_frame_.c_str());

perception/autoware_compare_map_segmentation/src/voxel_distance_based_compare_map_filter/node.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void VoxelDistanceBasedStaticMapLoader::onMapCallback(
3333
pcl::fromROSMsg<pcl::PointXYZ>(*map, map_pcl);
3434
const auto map_pcl_ptr = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>(map_pcl);
3535

36-
(*mutex_ptr_).lock();
3736
map_ptr_ = map_pcl_ptr;
3837
*tf_map_input_frame_ = map_ptr_->header.frame_id;
3938
// voxel
@@ -53,12 +52,15 @@ void VoxelDistanceBasedStaticMapLoader::onMapCallback(
5352
}
5453
}
5554
tree_->setInputCloud(map_ptr_);
56-
(*mutex_ptr_).unlock();
55+
is_initialized_.store(true, std::memory_order_release);
5756
}
5857

5958
bool VoxelDistanceBasedStaticMapLoader::is_close_to_map(
6059
const pcl::PointXYZ & point, const double distance_threshold)
6160
{
61+
if (!is_initialized_.load(std::memory_order_acquire)) {
62+
return false;
63+
}
6264
if (voxel_map_ptr_ == NULL) {
6365
return false;
6466
}
@@ -124,11 +126,10 @@ VoxelDistanceBasedCompareMapFilterComponent::VoxelDistanceBasedCompareMapFilterC
124126
rclcpp::CallbackGroup::SharedPtr main_callback_group;
125127
main_callback_group = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
126128
voxel_distance_based_map_loader_ = std::make_unique<VoxelDistanceBasedDynamicMapLoader>(
127-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_,
128-
main_callback_group);
129+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, main_callback_group);
129130
} else {
130131
voxel_distance_based_map_loader_ = std::make_unique<VoxelDistanceBasedStaticMapLoader>(
131-
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_, &mutex_);
132+
this, distance_threshold_, downsize_ratio_z_axis, &tf_input_frame_);
132133
}
133134
}
134135

perception/autoware_compare_map_segmentation/src/voxel_distance_based_compare_map_filter/node.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class VoxelDistanceBasedStaticMapLoader : public VoxelGridStaticMapLoader
4343
public:
4444
explicit VoxelDistanceBasedStaticMapLoader(
4545
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
46-
std::string * tf_map_input_frame, std::mutex * mutex)
47-
: VoxelGridStaticMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex)
46+
std::string * tf_map_input_frame)
47+
: VoxelGridStaticMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame)
4848
{
4949
RCLCPP_INFO(logger_, "VoxelDistanceBasedStaticMapLoader initialized.\n");
5050
}
@@ -61,10 +61,9 @@ class VoxelDistanceBasedDynamicMapLoader : public VoxelGridDynamicMapLoader
6161
public:
6262
explicit VoxelDistanceBasedDynamicMapLoader(
6363
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
64-
std::string * tf_map_input_frame, std::mutex * mutex,
65-
rclcpp::CallbackGroup::SharedPtr main_callback_group)
64+
std::string * tf_map_input_frame, rclcpp::CallbackGroup::SharedPtr main_callback_group)
6665
: VoxelGridDynamicMapLoader(
67-
node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex, main_callback_group)
66+
node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, main_callback_group)
6867
{
6968
RCLCPP_INFO(logger_, "VoxelDistanceBasedDynamicMapLoader initialized.\n");
7069
}
@@ -117,9 +116,8 @@ class VoxelDistanceBasedDynamicMapLoader : public VoxelGridDynamicMapLoader
117116
current_voxel_grid_list_item.map_cell_kdtree = tree_tmp;
118117

119118
// add
120-
(*mutex_ptr_).lock();
119+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
121120
current_voxel_grid_dict_.insert({map_cell_to_add.cell_id, current_voxel_grid_list_item});
122-
(*mutex_ptr_).unlock();
123121
}
124122
};
125123

perception/autoware_compare_map_segmentation/src/voxel_grid_map_loader/voxel_grid_map_loader.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ namespace autoware::compare_map_segmentation
1818
{
1919
VoxelGridMapLoader::VoxelGridMapLoader(
2020
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
21-
std::string * tf_map_input_frame, std::mutex * mutex)
21+
std::string * tf_map_input_frame)
2222
: logger_(node->get_logger()),
2323
voxel_leaf_size_(leaf_size),
2424
downsize_ratio_z_axis_(downsize_ratio_z_axis)
2525
{
2626
tf_map_input_frame_ = tf_map_input_frame;
27-
mutex_ptr_ = mutex;
2827

2928
downsampled_map_pub_ = node->create_publisher<sensor_msgs::msg::PointCloud2>(
3029
"debug/downsampled_map/pointcloud", rclcpp::QoS{1}.transient_local());
@@ -245,8 +244,8 @@ bool VoxelGridMapLoader::is_in_voxel(
245244

246245
VoxelGridStaticMapLoader::VoxelGridStaticMapLoader(
247246
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
248-
std::string * tf_map_input_frame, std::mutex * mutex)
249-
: VoxelGridMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex)
247+
std::string * tf_map_input_frame)
248+
: VoxelGridMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame)
250249
{
251250
voxel_leaf_size_z_ = voxel_leaf_size_ * downsize_ratio_z_axis_;
252251
sub_map_ = node->create_subscription<sensor_msgs::msg::PointCloud2>(
@@ -262,13 +261,12 @@ void VoxelGridStaticMapLoader::onMapCallback(
262261
pcl::fromROSMsg<pcl::PointXYZ>(*map, map_pcl);
263262
const auto map_pcl_ptr = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>(map_pcl);
264263
*tf_map_input_frame_ = map_pcl_ptr->header.frame_id;
265-
(*mutex_ptr_).lock();
266264
voxel_map_ptr_.reset(new pcl::PointCloud<pcl::PointXYZ>);
267265
voxel_grid_.setLeafSize(voxel_leaf_size_, voxel_leaf_size_, voxel_leaf_size_z_);
268266
voxel_grid_.setInputCloud(map_pcl_ptr);
269267
voxel_grid_.setSaveLeafLayout(true);
270268
voxel_grid_.filter(*voxel_map_ptr_);
271-
(*mutex_ptr_).unlock();
269+
is_initialized_.store(true, std::memory_order_release);
272270

273271
if (debug_) {
274272
publish_downsampled_map(*voxel_map_ptr_);
@@ -277,6 +275,9 @@ void VoxelGridStaticMapLoader::onMapCallback(
277275
bool VoxelGridStaticMapLoader::is_close_to_map(
278276
const pcl::PointXYZ & point, const double distance_threshold)
279277
{
278+
if (!is_initialized_.load(std::memory_order_acquire)) {
279+
return false;
280+
}
280281
if (is_close_to_neighbor_voxels(point, distance_threshold, voxel_map_ptr_, voxel_grid_)) {
281282
return true;
282283
}
@@ -285,9 +286,8 @@ bool VoxelGridStaticMapLoader::is_close_to_map(
285286

286287
VoxelGridDynamicMapLoader::VoxelGridDynamicMapLoader(
287288
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
288-
std::string * tf_map_input_frame, std::mutex * mutex,
289-
rclcpp::CallbackGroup::SharedPtr main_callback_group)
290-
: VoxelGridMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame, mutex)
289+
std::string * tf_map_input_frame, rclcpp::CallbackGroup::SharedPtr main_callback_group)
290+
: VoxelGridMapLoader(node, leaf_size, downsize_ratio_z_axis, tf_map_input_frame)
291291
{
292292
voxel_leaf_size_z_ = voxel_leaf_size_ * downsize_ratio_z_axis_;
293293
auto timer_interval_ms = node->declare_parameter<int>("timer_interval_ms");

perception/autoware_compare_map_segmentation/src/voxel_grid_map_loader/voxel_grid_map_loader.hpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <pcl/search/pcl_search.h>
2727
#include <pcl_conversions/pcl_conversions.h>
2828

29+
#include <atomic>
2930
#include <map>
3031
#include <memory>
3132
#include <string>
@@ -85,7 +86,6 @@ class VoxelGridMapLoader
8586
{
8687
protected:
8788
rclcpp::Logger logger_;
88-
std::mutex * mutex_ptr_;
8989
double voxel_leaf_size_;
9090
double voxel_leaf_size_z_{};
9191
double downsize_ratio_z_axis_;
@@ -98,7 +98,7 @@ class VoxelGridMapLoader
9898
typedef typename PointCloud::Ptr PointCloudPtr;
9999
explicit VoxelGridMapLoader(
100100
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
101-
std::string * tf_map_input_frame, std::mutex * mutex);
101+
std::string * tf_map_input_frame);
102102

103103
virtual bool is_close_to_map(const pcl::PointXYZ & point, const double distance_threshold) = 0;
104104
static bool is_close_to_neighbor_voxels(
@@ -121,11 +121,12 @@ class VoxelGridStaticMapLoader : public VoxelGridMapLoader
121121
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_map_;
122122
VoxelGridPointXYZ voxel_grid_;
123123
PointCloudPtr voxel_map_ptr_;
124+
std::atomic_bool is_initialized_{false};
124125

125126
public:
126127
explicit VoxelGridStaticMapLoader(
127128
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
128-
std::string * tf_map_input_frame, std::mutex * mutex);
129+
std::string * tf_map_input_frame);
129130
virtual void onMapCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr map);
130131
bool is_close_to_map(const pcl::PointXYZ & point, const double distance_threshold) override;
131132
};
@@ -145,6 +146,7 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
145146

146147
/** \brief Map to hold loaded map grid id and it's voxel filter */
147148
VoxelGridDict current_voxel_grid_dict_;
149+
std::mutex dynamic_map_loader_mutex_;
148150
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_kinematic_state_;
149151

150152
std::optional<geometry_msgs::msg::Point> current_position_ = std::nullopt;
@@ -182,8 +184,7 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
182184
public:
183185
explicit VoxelGridDynamicMapLoader(
184186
rclcpp::Node * node, double leaf_size, double downsize_ratio_z_axis,
185-
std::string * tf_map_input_frame, std::mutex * mutex,
186-
rclcpp::CallbackGroup::SharedPtr main_callback_group);
187+
std::string * tf_map_input_frame, rclcpp::CallbackGroup::SharedPtr main_callback_group);
187188
void onEstimatedPoseCallback(nav_msgs::msg::Odometry::ConstSharedPtr msg);
188189

189190
void timer_callback();
@@ -194,17 +195,19 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
194195
bool is_close_to_next_map_grid(
195196
const pcl::PointXYZ & point, const int current_map_grid_index, const double distance_threshold);
196197

197-
inline pcl::PointCloud<pcl::PointXYZ> getCurrentDownsampledMapPc() const
198+
inline pcl::PointCloud<pcl::PointXYZ> getCurrentDownsampledMapPc()
198199
{
199200
pcl::PointCloud<pcl::PointXYZ> output;
201+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
200202
for (const auto & kv : current_voxel_grid_dict_) {
201203
output = output + *(kv.second.map_cell_pc_ptr);
202204
}
203205
return output;
204206
}
205-
inline std::vector<std::string> getCurrentMapIDs() const
207+
inline std::vector<std::string> getCurrentMapIDs()
206208
{
207209
std::vector<std::string> current_map_ids{};
210+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
208211
for (auto & kv : current_voxel_grid_dict_) {
209212
current_map_ids.push_back(kv.first);
210213
}
@@ -243,9 +246,9 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
243246
return;
244247
}
245248

246-
(*mutex_ptr_).lock();
247249
current_voxel_grid_array_.assign(
248250
map_grids_x_ * map_grid_size_y_, std::make_shared<MapGridVoxelInfo>());
251+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
249252
for (const auto & kv : current_voxel_grid_dict_) {
250253
int index = static_cast<int>(
251254
std::floor((kv.second.min_b_x - origin_x_) / map_grid_size_x_) +
@@ -256,14 +259,12 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
256259
}
257260
current_voxel_grid_array_.at(index) = std::make_shared<MapGridVoxelInfo>(kv.second);
258261
}
259-
(*mutex_ptr_).unlock();
260262
}
261263

262264
inline void removeMapCell(const std::string & map_cell_id_to_remove)
263265
{
264-
(*mutex_ptr_).lock();
266+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
265267
current_voxel_grid_dict_.erase(map_cell_id_to_remove);
266-
(*mutex_ptr_).unlock();
267268
}
268269

269270
virtual inline void addMapCellAndFilter(
@@ -310,9 +311,8 @@ class VoxelGridDynamicMapLoader : public VoxelGridMapLoader
310311
current_voxel_grid_list_item.map_cell_pc_ptr.reset(new pcl::PointCloud<pcl::PointXYZ>);
311312
current_voxel_grid_list_item.map_cell_pc_ptr = std::move(map_cell_downsampled_pc_ptr_tmp);
312313
// add
313-
(*mutex_ptr_).lock();
314+
std::lock_guard<std::mutex> lock(dynamic_map_loader_mutex_);
314315
current_voxel_grid_dict_.insert({map_cell_to_add.cell_id, current_voxel_grid_list_item});
315-
(*mutex_ptr_).unlock();
316316
}
317317
};
318318

0 commit comments

Comments
 (0)