Compare commits

...

4 Commits
2.4.2 ... foxy

Author SHA1 Message Date
Dharini Dutia
b0c25d5f22 2.4.3 2023-05-27 02:23:33 +00:00
Dharini Dutia
6a7d35a588 updated changelog
Signed-off-by: Dharini Dutia <dharini@openrobotics.org>
2023-05-27 02:15:41 +00:00
mergify[bot]
9c82f6c925 Do not attempt to use void allocators for memory allocation. (backport #1657) (#2004)
* Do not attempt to use void allocators for memory allocation. (#1657)

Keep a rebound allocator for byte-sized memory blocks around
for publisher and subscription options.

Follow-up after 1fc2d58799

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
(cherry picked from commit 0659d829ce)

# Conflicts:
#	rclcpp/include/rclcpp/publisher_options.hpp
#	rclcpp/include/rclcpp/subscription_options.hpp

* fix conflicts

Signed-off-by: Dharini Dutia <dharini@openrobotics.org>

---------

Signed-off-by: Dharini Dutia <dharini@openrobotics.org>
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
Co-authored-by: Dharini Dutia <dharini@openrobotics.org>
2023-05-16 09:54:03 -07:00
mergify[bot]
cb226baa5b Revert "Revert "extract the result response before the callback is is… (backport #2152) (#2153)
* Revert "Revert "extract the result response before the callback is issued. (#2133)" (#2148)" (#2152)

This reverts commit 19a666f1c9.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
(cherry picked from commit b2b7bdeac1)

* address cpplint error.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>

---------

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
2023-04-03 21:46:35 -07:00
12 changed files with 106 additions and 20 deletions

View File

@@ -2,6 +2,11 @@
Changelog for package rclcpp
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.4.3 (2023-05-27)
------------------
* Do not attempt to use void allocators for memory allocation. (backport `#1657 <https://github.com/ros2/rclcpp/issues/1657>`_) (`#2004 <https://github.com/ros2/rclcpp/issues/2004>`_)
* Contributors: Michel Hidalgo
2.4.2 (2022-07-25)
------------------
* Add statistics for handle_loaned_message (`#1927 <https://github.com/ros2/rclcpp/issues/1927>`_) (`#1934 <https://github.com/ros2/rclcpp/issues/1934>`_)

View File

@@ -72,10 +72,7 @@ struct PublisherOptionsWithAllocator : public PublisherOptionsBase
to_rcl_publisher_options(const rclcpp::QoS & qos) const
{
rcl_publisher_options_t result = rcl_publisher_get_default_options();
using AllocatorTraits = std::allocator_traits<Allocator>;
using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
auto message_alloc = std::make_shared<MessageAllocatorT>(*this->get_allocator().get());
result.allocator = rclcpp::allocator::get_rcl_allocator<MessageT>(*message_alloc);
result.allocator = this->get_rcl_allocator();
result.qos = qos.get_rmw_qos_profile();
// Apply payload to rcl_publisher_options if necessary.
@@ -96,6 +93,28 @@ struct PublisherOptionsWithAllocator : public PublisherOptionsBase
}
return this->allocator;
}
private:
using PlainAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
rcl_allocator_t
get_rcl_allocator() const
{
if (!plain_allocator_storage_) {
plain_allocator_storage_ =
std::make_shared<PlainAllocator>(*this->get_allocator());
}
return rclcpp::allocator::get_rcl_allocator<char>(*plain_allocator_storage_);
}
// This is a temporal workaround, to make sure that get_allocator()
// always returns a copy of the same allocator.
mutable std::shared_ptr<Allocator> allocator_storage_;
// This is a temporal workaround, to keep the plain allocator that backs
// up the rcl allocator returned in rcl_publisher_options_t alive.
mutable std::shared_ptr<PlainAllocator> plain_allocator_storage_;
};
using PublisherOptions = PublisherOptionsWithAllocator<std::allocator<void>>;

View File

@@ -99,10 +99,7 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase
to_rcl_subscription_options(const rclcpp::QoS & qos) const
{
rcl_subscription_options_t result = rcl_subscription_get_default_options();
using AllocatorTraits = std::allocator_traits<Allocator>;
using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
auto message_alloc = std::make_shared<MessageAllocatorT>(*this->get_allocator().get());
result.allocator = allocator::get_rcl_allocator<MessageT>(*message_alloc);
result.allocator = this->get_rcl_allocator();
result.qos = qos.get_rmw_qos_profile();
result.rmw_subscription_options.ignore_local_publications = this->ignore_local_publications;
@@ -123,6 +120,28 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase
}
return this->allocator;
}
private:
using PlainAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
rcl_allocator_t
get_rcl_allocator() const
{
if (!plain_allocator_storage_) {
plain_allocator_storage_ =
std::make_shared<PlainAllocator>(*this->get_allocator());
}
return rclcpp::allocator::get_rcl_allocator<char>(*plain_allocator_storage_);
}
// This is a temporal workaround, to make sure that get_allocator()
// always returns a copy of the same allocator.
mutable std::shared_ptr<Allocator> allocator_storage_;
// This is a temporal workaround, to keep the plain allocator that backs
// up the rcl allocator returned in rcl_subscription_options_t alive.
mutable std::shared_ptr<PlainAllocator> plain_allocator_storage_;
};
using SubscriptionOptions = SubscriptionOptionsWithAllocator<std::allocator<void>>;

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp</name>
<version>2.4.2</version>
<version>2.4.3</version>
<description>The ROS client library in C++.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>

View File

@@ -30,7 +30,7 @@
static uint32_t num_allocs = 0;
static uint32_t num_deallocs = 0;
// A very simple custom allocator. Counts calls to allocate and deallocate.
template<typename T = void>
template<typename T>
struct MyAllocator
{
public:
@@ -77,6 +77,33 @@ public:
};
};
// Explicit specialization for void
template<>
struct MyAllocator<void>
{
public:
using value_type = void;
using pointer = void *;
using const_pointer = const void *;
MyAllocator() noexcept
{
}
~MyAllocator() noexcept {}
template<typename U>
MyAllocator(const MyAllocator<U> &) noexcept
{
}
template<typename U>
struct rebind
{
typedef MyAllocator<U> other;
};
};
template<typename T, typename U>
constexpr bool operator==(
const MyAllocator<T> &,

View File

@@ -3,6 +3,11 @@ Changelog for package rclcpp_action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.4.3 (2023-05-27)
------------------
* Revert "Revert "extract the result response before the callback is is… (backport `#2152 <https://github.com/ros2/rclcpp/issues/2152>`_) (`#2153 <https://github.com/ros2/rclcpp/issues/2153>`_)
* Contributors: Tomoya Fujita
2.4.2 (2022-07-25)
------------------

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_action</name>
<version>2.4.2</version>
<version>2.4.3</version>
<description>Adds action APIs for C++.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>

View File

@@ -22,6 +22,7 @@
#include <memory>
#include <random>
#include <string>
#include <utility>
#include "rclcpp_action/client.hpp"
#include "rclcpp_action/exceptions.hpp"
@@ -314,14 +315,18 @@ ClientBase::handle_result_response(
const rmw_request_id_t & response_header,
std::shared_ptr<void> response)
{
std::lock_guard<std::mutex> guard(pimpl_->result_requests_mutex);
const int64_t & sequence_number = response_header.sequence_number;
if (pimpl_->pending_result_responses.count(sequence_number) == 0) {
RCLCPP_ERROR(pimpl_->logger, "unknown result response, ignoring...");
return;
ResponseCallback response_callback;
{
std::lock_guard<std::mutex> guard(pimpl_->result_requests_mutex);
const int64_t & sequence_number = response_header.sequence_number;
if (pimpl_->pending_result_responses.count(sequence_number) == 0) {
RCLCPP_ERROR(pimpl_->logger, "unknown result response, ignoring...");
return;
}
response_callback = std::move(pimpl_->pending_result_responses[sequence_number]);
pimpl_->pending_result_responses.erase(sequence_number);
}
pimpl_->pending_result_responses[sequence_number](response);
pimpl_->pending_result_responses.erase(sequence_number);
response_callback(response);
}
void

View File

@@ -2,6 +2,9 @@
Changelog for package rclcpp_components
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.4.3 (2023-05-27)
------------------
2.4.2 (2022-07-25)
------------------

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_components</name>
<version>2.4.2</version>
<version>2.4.3</version>
<description>Package containing tools for dynamically loadable components</description>
<maintainer email="michael@openrobotics.org">Michael Carroll</maintainer>
<license>Apache License 2.0</license>

View File

@@ -3,6 +3,9 @@ Changelog for package rclcpp_lifecycle
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2.4.3 (2023-05-27)
------------------
2.4.2 (2022-07-25)
------------------

View File

@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rclcpp_lifecycle</name>
<version>2.4.2</version>
<version>2.4.3</version>
<description>Package containing a prototype for lifecycle implementation</description>
<maintainer email="karsten@osrfoundation.org">Karsten Knese</maintainer>
<license>Apache License 2.0</license>