Fix lock-order-inversion (potential deadlock) (#1135)

Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
This commit is contained in:
tomoya 2020-05-28 07:06:50 +09:00 committed by GitHub
parent eff11d61bb
commit e3abe8bf7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -368,9 +368,11 @@ rclcpp::Event::SharedPtr
NodeGraph::get_graph_event() NodeGraph::get_graph_event()
{ {
auto event = rclcpp::Event::make_shared(); auto event = rclcpp::Event::make_shared();
{
std::lock_guard<std::mutex> graph_changed_lock(graph_mutex_); std::lock_guard<std::mutex> graph_changed_lock(graph_mutex_);
graph_events_.push_back(event); graph_events_.push_back(event);
graph_users_count_++; graph_users_count_++;
}
// on first call, add node to graph_listener_ // on first call, add node to graph_listener_
if (should_add_to_graph_listener_.exchange(false)) { if (should_add_to_graph_listener_.exchange(false)) {
graph_listener_->add_node(this); graph_listener_->add_node(this);