Skip to content

Commit

Permalink
Enable loan messages on subscriptions of plain types.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany committed Apr 12, 2021
1 parent fc0f133 commit 6feb7cc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rmw_fastrtps_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "rmw_fastrtps_shared_cpp/namespace_prefix.hpp"
#include "rmw_fastrtps_shared_cpp/qos.hpp"
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "rmw_fastrtps_shared_cpp/subscription.hpp"
#include "rmw_fastrtps_shared_cpp/utils.hpp"

#include "rmw_fastrtps_cpp/identifier.hpp"
Expand Down Expand Up @@ -324,7 +325,7 @@ create_subscription(
return nullptr;
}
rmw_subscription->options = *subscription_options;
rmw_subscription->can_loan_messages = false;
rmw_fastrtps_shared_cpp::__init_subscription_for_loans(rmw_subscription);

topic.should_be_deleted = false;
cleanup_rmw_subscription.cancel();
Expand Down
3 changes: 2 additions & 1 deletion rmw_fastrtps_dynamic_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "rmw_fastrtps_shared_cpp/namespace_prefix.hpp"
#include "rmw_fastrtps_shared_cpp/qos.hpp"
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "rmw_fastrtps_shared_cpp/subscription.hpp"
#include "rmw_fastrtps_shared_cpp/utils.hpp"

#include "fastrtps/participant/Participant.h"
Expand Down Expand Up @@ -338,7 +339,7 @@ create_subscription(
memcpy(const_cast<char *>(rmw_subscription->topic_name), topic_name, strlen(topic_name) + 1);

rmw_subscription->options = *subscription_options;
rmw_subscription->can_loan_messages = false;
rmw_fastrtps_shared_cpp::__init_subscription_for_loans(rmw_subscription);

topic.should_be_deleted = false;
cleanup_rmw_subscription.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
namespace rmw_fastrtps_shared_cpp
{

RMW_FASTRTPS_SHARED_CPP_PUBLIC
void
__init_subscription_for_loans(
rmw_subscription_t * subscription);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
destroy_subscription(
Expand Down
21 changes: 21 additions & 0 deletions rmw_fastrtps_shared_cpp/src/rmw_take.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>

#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/serialized_message.h"
Expand All @@ -27,6 +29,7 @@
#include "rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp"
#include "rmw_fastrtps_shared_cpp/guid_utils.hpp"
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "rmw_fastrtps_shared_cpp/subscription.hpp"
#include "rmw_fastrtps_shared_cpp/TypeSupport.hpp"
#include "rmw_fastrtps_shared_cpp/utils.hpp"

Expand Down Expand Up @@ -377,10 +380,28 @@ struct LoanManager
eprosima::fastdds::dds::SampleInfoSeq info_seq{};
};

explicit LoanManager(const eprosima::fastrtps::ResourceLimitedContainerConfig & items_cfg)
: items(items_cfg)
{
}

std::mutex mtx;
eprosima::fastrtps::ResourceLimitedVector<Item> items RCPPUTILS_TSA_GUARDED_BY(mtx);
};

void
__init_subscription_for_loans(
rmw_subscription_t * subscription)
{
auto info = static_cast<CustomSubscriberInfo *>(subscription->data);
subscription->can_loan_messages = info->type_support_->is_plain();
if (subscription->can_loan_messages) {
const auto & qos = info->data_reader_->get_qos();
const auto & allocation_qos = qos.reader_resource_limits().outstanding_reads_allocation;
info->loan_manager_ = std::make_shared<LoanManager>(allocation_qos);
}
}

rmw_ret_t
__rmw_take_loaned_message_internal(
const char * identifier,
Expand Down

0 comments on commit 6feb7cc

Please sign in to comment.