Fix locking while modifying counter (#1454)
Clang with thread safety does not compile because num_nodes_since_last_loop_closure_ is modified without holding a mutex. This fixes it.master
parent
5253186cbe
commit
f060815a7f
|
@ -377,6 +377,7 @@ WorkItem::Result PoseGraph2D::ComputeConstraintsForNode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constraint_builder_.NotifyEndOfNode();
|
constraint_builder_.NotifyEndOfNode();
|
||||||
|
absl::MutexLock locker(&mutex_);
|
||||||
++num_nodes_since_last_loop_closure_;
|
++num_nodes_since_last_loop_closure_;
|
||||||
if (options_.optimize_every_n_nodes() > 0 &&
|
if (options_.optimize_every_n_nodes() > 0 &&
|
||||||
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
|
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
|
||||||
|
@ -997,6 +998,7 @@ transform::Rigid3d PoseGraph2D::GetLocalToGlobalTransform(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<int>> PoseGraph2D::GetConnectedTrajectories() const {
|
std::vector<std::vector<int>> PoseGraph2D::GetConnectedTrajectories() const {
|
||||||
|
absl::MutexLock locker(&mutex_);
|
||||||
return data_.trajectory_connectivity_state.Components();
|
return data_.trajectory_connectivity_state.Components();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,8 @@ class PoseGraph2D : public PoseGraph {
|
||||||
const std::vector<Constraint>& constraints) override;
|
const std::vector<Constraint>& constraints) override;
|
||||||
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
|
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
|
||||||
void RunFinalOptimization() 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
|
PoseGraphInterface::SubmapData GetSubmapData(const SubmapId& submap_id) const
|
||||||
LOCKS_EXCLUDED(mutex_) override;
|
LOCKS_EXCLUDED(mutex_) override;
|
||||||
MapById<SubmapId, PoseGraphInterface::SubmapData> GetAllSubmapData() const
|
MapById<SubmapId, PoseGraphInterface::SubmapData> GetAllSubmapData() const
|
||||||
|
|
|
@ -371,6 +371,7 @@ WorkItem::Result PoseGraph3D::ComputeConstraintsForNode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constraint_builder_.NotifyEndOfNode();
|
constraint_builder_.NotifyEndOfNode();
|
||||||
|
absl::MutexLock locker(&mutex_);
|
||||||
++num_nodes_since_last_loop_closure_;
|
++num_nodes_since_last_loop_closure_;
|
||||||
if (options_.optimize_every_n_nodes() > 0 &&
|
if (options_.optimize_every_n_nodes() > 0 &&
|
||||||
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
|
num_nodes_since_last_loop_closure_ > options_.optimize_every_n_nodes()) {
|
||||||
|
@ -1005,6 +1006,7 @@ transform::Rigid3d PoseGraph3D::GetLocalToGlobalTransform(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<int>> PoseGraph3D::GetConnectedTrajectories() const {
|
std::vector<std::vector<int>> PoseGraph3D::GetConnectedTrajectories() const {
|
||||||
|
absl::MutexLock locker(&mutex_);
|
||||||
return data_.trajectory_connectivity_state.Components();
|
return data_.trajectory_connectivity_state.Components();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,8 @@ class PoseGraph3D : public PoseGraph {
|
||||||
const std::vector<Constraint>& constraints) override;
|
const std::vector<Constraint>& constraints) override;
|
||||||
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
|
void AddTrimmer(std::unique_ptr<PoseGraphTrimmer> trimmer) override;
|
||||||
void RunFinalOptimization() 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
|
PoseGraph::SubmapData GetSubmapData(const SubmapId& submap_id) const
|
||||||
LOCKS_EXCLUDED(mutex_) override;
|
LOCKS_EXCLUDED(mutex_) override;
|
||||||
MapById<SubmapId, SubmapData> GetAllSubmapData() const
|
MapById<SubmapId, SubmapData> GetAllSubmapData() const
|
||||||
|
|
Loading…
Reference in New Issue