Skip to content

Commit

Permalink
Fix locking while modifying counter (#1454)
Browse files Browse the repository at this point in the history
Clang with thread safety does not compile because
num_nodes_since_last_loop_closure_
is modified without holding a mutex.
This fixes it.
  • Loading branch information
gaschler committed Oct 25, 2018
1 parent 5253186 commit f060815
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cartographer/mapping/internal/2d/pose_graph_2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ WorkItem::Result PoseGraph2D::ComputeConstraintsForNode(
}
}
constraint_builder_.NotifyEndOfNode();
absl::MutexLock locker(&mutex_);
++num_nodes_since_last_loop_closure_;
if (options_.optimize_every_n_nodes() > 0 &&
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
Expand Down Expand Up @@ -997,6 +998,7 @@ transform::Rigid3d PoseGraph2D::GetLocalToGlobalTransform(
}

std::vector<std::vector<int>> PoseGraph2D::GetConnectedTrajectories() const {
absl::MutexLock locker(&mutex_);
return data_.trajectory_connectivity_state.Components();
}

Expand Down
3 changes: 2 additions & 1 deletion cartographer/mapping/internal/2d/pose_graph_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class PoseGraph2D : public PoseGraph {
const std::vector<Constraint>& constraints) override;
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
void RunFinalOptimization() override;
std::vector<std::vector<int>> GetConnectedTrajectories() const override;
std::vector<std::vector<int>> GetConnectedTrajectories() const override
LOCKS_EXCLUDED(mutex_);
PoseGraphInterface::SubmapData GetSubmapData(const SubmapId& submap_id) const
LOCKS_EXCLUDED(mutex_) override;
MapById<SubmapId, PoseGraphInterface::SubmapData> GetAllSubmapData() const
Expand Down
2 changes: 2 additions & 0 deletions cartographer/mapping/internal/3d/pose_graph_3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ WorkItem::Result PoseGraph3D::ComputeConstraintsForNode(
}
}
constraint_builder_.NotifyEndOfNode();
absl::MutexLock locker(&mutex_);
++num_nodes_since_last_loop_closure_;
if (options_.optimize_every_n_nodes() > 0 &&
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
Expand Down Expand Up @@ -1005,6 +1006,7 @@ transform::Rigid3d PoseGraph3D::GetLocalToGlobalTransform(
}

std::vector<std::vector<int>> PoseGraph3D::GetConnectedTrajectories() const {
absl::MutexLock locker(&mutex_);
return data_.trajectory_connectivity_state.Components();
}

Expand Down
3 changes: 2 additions & 1 deletion cartographer/mapping/internal/3d/pose_graph_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class PoseGraph3D : public PoseGraph {
const std::vector<Constraint>& constraints) override;
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
void RunFinalOptimization() override;
std::vector<std::vector<int>> GetConnectedTrajectories() const override;
std::vector<std::vector<int>> GetConnectedTrajectories() const override
LOCKS_EXCLUDED(mutex_);
PoseGraph::SubmapData GetSubmapData(const SubmapId& submap_id) const
LOCKS_EXCLUDED(mutex_) override;
MapById<SubmapId, SubmapData> GetAllSubmapData() const
Expand Down

0 comments on commit f060815

Please sign in to comment.