From 0e9616afc5c3580c79fe80c7de8450b6b9198209 Mon Sep 17 00:00:00 2001 From: Shoji Morita Date: Thu, 10 Aug 2023 09:54:04 +0900 Subject: [PATCH] Updated the rcl interface in accordance with the specifications outlined in the DRAFT REP shared below. https://discourse.ros.org/t/adding-thread-attributes-configuration-in-ros-2-framework/30701/5 Signed-off-by: Shoji Morita --- .../rclcpp/executors/multi_threaded_executor.cpp | 12 ++++-------- .../rclcpp/executors/single_threaded_executor.cpp | 14 +++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp index c54f0c33e1..079f5ddb5b 100644 --- a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp @@ -38,19 +38,15 @@ MultiThreadedExecutor::MultiThreadedExecutor( thread_attributes_(nullptr) { bool has_number_of_threads_arg = number_of_threads > 0; - rcl_ret_t ret; number_of_threads_ = number_of_threads > 0 ? number_of_threads : std::max(rcpputils::Thread::hardware_concurrency(), 2U); - ret = rcl_arguments_get_thread_attrs( - &options.context->get_rcl_context()->global_arguments, - &thread_attributes_); - if (ret != RCL_RET_OK) { - ret = rcl_context_get_thread_attrs( - options.context->get_rcl_context().get(), - &thread_attributes_); + if (rcutils_thread_attrs_t * attrs = rcl_context_get_thread_attrs( + options.context->get_rcl_context().get())) + { + thread_attributes_ = attrs; } if (has_number_of_threads_arg && thread_attributes_ && diff --git a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp index cb471992b4..c4de845c51 100644 --- a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp @@ -24,16 +24,12 @@ SingleThreadedExecutor::SingleThreadedExecutor(const rclcpp::ExecutorOptions & o : rclcpp::Executor(options), thread_attributes_(nullptr) { - rcl_ret_t ret; - - ret = rcl_arguments_get_thread_attrs( - &options.context->get_rcl_context()->global_arguments, - &thread_attributes_); - if (ret != RCL_RET_OK) { - ret = rcl_context_get_thread_attrs( - options.context->get_rcl_context().get(), - &thread_attributes_); + if (rcutils_thread_attrs_t * attrs = rcl_context_get_thread_attrs( + options.context->get_rcl_context().get())) + { + thread_attributes_ = attrs; } + if (thread_attributes_ && thread_attributes_->num_attributes != 1) { RCLCPP_WARN( rclcpp::get_logger("rclcpp"),