Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid retaining ownership of the rcl context #946

Merged
merged 4 commits into from
Jan 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rclcpp/src/rclcpp/graph_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ GraphListener::start_if_not_started()
if (!is_started_) {
// Initialize the wait set before starting.
auto parent_context = parent_context_.lock();
if (!parent_context) {
throw std::runtime_error("parent context was destroyed");
}
rcl_ret_t ret = rcl_wait_set_init(
&wait_set_,
0, // number_of_subscriptions
Expand Down Expand Up @@ -142,6 +145,11 @@ GraphListener::run_loop()
std::lock_guard<std::mutex> nodes_lock(node_graph_interfaces_mutex_, std::adopt_lock);
// Ensure that the context doesn't go out of scope.
auto parent_context = parent_context_.lock();
if (!parent_context) {
// the parent context may be destroyed before this loop is stopped.
// in that case, just return silently.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: if a comment has punctuation then it should be a sentence and should have capitalization

// this is ok
// This is also ok.
// some_variable_name at the beginning makes a lack of capitalization ok too.

// this is weird.
// Weird because not a sentence, actually sentence fragment.
// not weird because not a sentence, so sentence fragments are ok

return;
}

// Resize the wait set if necessary.
const size_t node_graph_interfaces_size = node_graph_interfaces_.size();
Expand Down