-
Notifications
You must be signed in to change notification settings - Fork 543
Move ownership of shutdown_guard_condition to executors/graph_listener #1404
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
Changes from 4 commits
aece93b
fb8774b
2297071
6e8e157
564993c
88ed73e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,30 +40,80 @@ using rclcpp::Executor; | |
| using rclcpp::ExecutorOptions; | ||
| using rclcpp::FutureReturnCode; | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| std::shared_ptr<rcl_guard_condition_t> | ||
| create_shutdown_guard_condition(std::shared_ptr<rclcpp::Context> context) | ||
| { | ||
| auto custom_deleter = [](rcl_guard_condition_t * guard_condition) { | ||
| rcl_ret_t ret = rcl_guard_condition_fini(guard_condition); | ||
| if (RCL_RET_OK != ret) { | ||
| RCLCPP_ERROR( | ||
| rclcpp::get_logger("rclcpp"), | ||
| "Failed to finalize shutdown_guard_condition, leaking memory!"); | ||
| } | ||
| }; | ||
|
|
||
| auto shutdown_guard_condition = | ||
| std::shared_ptr<rcl_guard_condition_t>(new rcl_guard_condition_t, custom_deleter); | ||
| *shutdown_guard_condition = rcl_get_zero_initialized_guard_condition(); | ||
|
|
||
| rcl_ret_t ret = rcl_guard_condition_init( | ||
| shutdown_guard_condition.get(), | ||
| context->get_rcl_context().get(), | ||
| rcl_guard_condition_get_default_options()); | ||
| if (RCL_RET_OK != ret) { | ||
| throw_from_rcl_error(ret, "failed to create shutdown guard condition"); | ||
| } | ||
|
|
||
| context->on_shutdown( | ||
| [weak_shutdown_guard_condition = | ||
| std::weak_ptr<rcl_guard_condition_t>(shutdown_guard_condition)]() | ||
| { | ||
| auto shared_guard_condition = weak_shutdown_guard_condition.lock(); | ||
| if (nullptr != shared_guard_condition) { | ||
| rcl_ret_t status = rcl_trigger_guard_condition(shared_guard_condition.get()); | ||
| if (status != RCL_RET_OK) { | ||
| RCUTILS_LOG_ERROR_NAMED( | ||
| "rclcpp", | ||
| "failed to trigger guard condition in Context shutdown callback(): %s", | ||
| rcl_get_error_string().str); | ||
| } | ||
| } | ||
| }); | ||
| return shutdown_guard_condition; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| Executor::Executor(const rclcpp::ExecutorOptions & options) | ||
| : spinning(false), | ||
| memory_strategy_(options.memory_strategy) | ||
| { | ||
| // Store the context for later use. | ||
| context_ = options.context; | ||
|
|
||
| rcl_guard_condition_options_t guard_condition_options = rcl_guard_condition_get_default_options(); | ||
| rcl_ret_t ret = rcl_guard_condition_init( | ||
| &interrupt_guard_condition_, options.context->get_rcl_context().get(), guard_condition_options); | ||
| &interrupt_guard_condition_, context_->get_rcl_context().get(), guard_condition_options); | ||
| if (RCL_RET_OK != ret) { | ||
| throw_from_rcl_error(ret, "Failed to create interrupt guard condition in Executor constructor"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't hit anymore.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner Any suggestion to cover this line without adding a mock that fails in the second call to Maybe fault injection works for this, I will try to give it a try. P.S.: I don't think that hitting this line matters, as overall coverage has improved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, that's my opinion too. If overall coverage is improving, then its OK to lose a line like this. If it becomes important, we can always revisit it later.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fault injection tools were intended for situations like this, but I think it's fine without. |
||
| } | ||
|
|
||
| // Register a shutdown hook for the executor with context | ||
| shutdown_guard_condition_ = create_shutdown_guard_condition(context_); | ||
|
|
||
| // The number of guard conditions is always at least 2: 1 for the ctrl-c guard cond, | ||
| // and one for the executor's guard cond (interrupt_guard_condition_) | ||
|
|
||
| // Put the global ctrl-c guard condition in | ||
| memory_strategy_->add_guard_condition(options.context->get_interrupt_guard_condition(&wait_set_)); | ||
| memory_strategy_->add_guard_condition(shutdown_guard_condition_.get()); | ||
|
|
||
| // Put the executor's guard condition in | ||
| memory_strategy_->add_guard_condition(&interrupt_guard_condition_); | ||
| rcl_allocator_t allocator = memory_strategy_->get_allocator(); | ||
|
|
||
| // Store the context for later use. | ||
| context_ = options.context; | ||
|
|
||
| ret = rcl_wait_set_init( | ||
| &wait_set_, | ||
| 0, 2, 0, 0, 0, 0, | ||
|
|
@@ -129,8 +179,7 @@ Executor::~Executor() | |
| rcl_reset_error(); | ||
| } | ||
| // Remove and release the sigint guard condition | ||
| memory_strategy_->remove_guard_condition(context_->get_interrupt_guard_condition(&wait_set_)); | ||
| context_->release_interrupt_guard_condition(&wait_set_, std::nothrow); | ||
| memory_strategy_->remove_guard_condition(shutdown_guard_condition_.get()); | ||
| } | ||
|
|
||
| std::vector<rclcpp::CallbackGroup::WeakPtr> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.