Compare commits

...

3 Commits

Author SHA1 Message Date
CY Chen
0b4d3d01c6 Add acceptable_buffer_backends field in SubscriptionOptionsBase
Signed-off-by: CY Chen <cyc@nvidia.com>
2026-03-16 17:19:13 +00:00
Danil
b6e9b4c9b4 Expose ServiceType in Service public API (#3088)
Signed-off-by: Danil <danil.nev@gmail.com>
2026-03-12 09:53:26 -07:00
solo
8cd4d47ec5 Avoid unecessary creation of MultiThreadedExecutor (#3090)
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
2026-03-12 15:59:22 +01:00
4 changed files with 31 additions and 5 deletions

View File

@@ -80,7 +80,7 @@ public:
node_base,
*rclcpp::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *ts_lib),
topic_name,
options.to_rcl_subscription_options(qos),
force_cpu_buffer_backend_(options).to_rcl_subscription_options(qos),
options.event_callbacks,
options.use_default_callbacks,
DeliveredMessageKind::SERIALIZED_MESSAGE),
@@ -182,6 +182,17 @@ public:
private:
RCLCPP_DISABLE_COPY(GenericSubscription)
template<typename AllocatorT>
static rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>
force_cpu_buffer_backend_(
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options)
{
auto opts = options;
opts.acceptable_buffer_backends = "cpu";
return opts;
}
AnySubscriptionCallback<rclcpp::SerializedMessage, std::allocator<void>> any_callback_;
// The type support library should stay loaded, so it is stored in the GenericSubscription
std::shared_ptr<rcpputils::SharedLibrary> ts_lib_;

View File

@@ -287,6 +287,7 @@ class Service
public std::enable_shared_from_this<Service<ServiceT>>
{
public:
using ServiceType = ServiceT;
using CallbackType = std::function<
void (
const std::shared_ptr<typename ServiceT::Request>,

View File

@@ -89,6 +89,15 @@ struct SubscriptionOptionsBase
QosOverridingOptions qos_overriding_options;
ContentFilterOptions content_filter_options;
/// Acceptable buffer backend names for this subscription.
/**
* Empty string or "cpu" means CPU-only (default for backward compatibility).
* "any" means all installed backends are acceptable.
* Comma-separated for specific backends, e.g. "cuda,demo".
* CPU is always implicitly acceptable regardless of this value.
*/
std::string acceptable_buffer_backends{"cpu"};
};
/// Structure containing optional configuration for Subscriptions.
@@ -145,6 +154,11 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase
}
}
if (!acceptable_buffer_backends.empty()) {
result.rmw_subscription_options.acceptable_buffer_backends =
acceptable_buffer_backends.c_str();
}
return result;
}

View File

@@ -24,16 +24,16 @@ int main(int argc, char * argv[])
/// Component container with a multi-threaded executor.
rclcpp::init(argc, argv);
auto exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
auto node = std::make_shared<rclcpp_components::ComponentManager>();
rclcpp::executors::MultiThreadedExecutor::SharedPtr exec = nullptr;
const auto node = std::make_shared<rclcpp_components::ComponentManager>();
if (node->has_parameter("thread_num")) {
const auto thread_num = node->get_parameter("thread_num").as_int();
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>(
rclcpp::ExecutorOptions{}, thread_num);
node->set_executor(exec);
} else {
node->set_executor(exec);
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
}
node->set_executor(exec);
exec->add_node(node);
exec->spin();