Skip to content

Commit

Permalink
Fix assertion in TopicPayloadPool::release_history (#5008)
Browse files Browse the repository at this point in the history
* Refs #21272: Fix pool configuration when type is plain changed to PREALLOCATED

Signed-off-by: Mario Dominguez <[email protected]>

* Refs #21272. Keep memory mode on `pool_config_`.

Signed-off-by: Miguel Company <[email protected]>

---------

Signed-off-by: Mario Dominguez <[email protected]>
Signed-off-by: Miguel Company <[email protected]>
Co-authored-by: Miguel Company <[email protected]>
  • Loading branch information
Mario-DL and MiguelCompany authored Jul 1, 2024
1 parent c3da9e0 commit 00b127c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ ReturnCode_t DataWriterImpl::enable()
topic_att, type_->m_typeSize, qos_.endpoint().history_memory_policy);
pool_config_ = PoolConfig::from_history_attributes(history_att);

// When the user requested PREALLOCATED_WITH_REALLOC, but we know the type cannot
// grow, we translate the policy into bare PREALLOCATED
if (PREALLOCATED_WITH_REALLOC_MEMORY_MODE == pool_config_.memory_policy &&
(type_->is_bounded() || type_->is_plain(data_representation_)))
{
pool_config_.memory_policy = PREALLOCATED_MEMORY_MODE;
}

WriterAttributes w_att;
w_att.endpoint.durabilityKind = qos_.durability().durabilityKind();
w_att.endpoint.endpointKind = WRITER;
Expand Down Expand Up @@ -2056,28 +2064,19 @@ std::shared_ptr<IPayloadPool> DataWriterImpl::get_payload_pool()
{
if (!payload_pool_)
{
PoolConfig config = pool_config_;

// When the user requested PREALLOCATED_WITH_REALLOC, but we know the type cannot
// grow, we translate the policy into bare PREALLOCATED
if (PREALLOCATED_WITH_REALLOC_MEMORY_MODE == config.memory_policy &&
(type_->is_bounded() || type_->is_plain(data_representation_)))
{
config.memory_policy = PREALLOCATED_MEMORY_MODE;
}

// Avoid calling the serialization size functors on PREALLOCATED mode
fixed_payload_size_ = config.memory_policy == PREALLOCATED_MEMORY_MODE ? config.payload_initial_size : 0u;
fixed_payload_size_ =
pool_config_.memory_policy == PREALLOCATED_MEMORY_MODE ? pool_config_.payload_initial_size : 0u;

// Get payload pool reference and allocate space for our history
if (is_data_sharing_compatible_)
{
payload_pool_ = DataSharingPayloadPool::get_writer_pool(config);
payload_pool_ = DataSharingPayloadPool::get_writer_pool(pool_config_);
}
else
{
payload_pool_ = TopicPayloadPoolRegistry::get(topic_->get_name(), config);
if (!std::static_pointer_cast<ITopicPayloadPool>(payload_pool_)->reserve_history(config, false))
payload_pool_ = TopicPayloadPoolRegistry::get(topic_->get_name(), pool_config_);
if (!std::static_pointer_cast<ITopicPayloadPool>(payload_pool_)->reserve_history(pool_config_, false))
{
payload_pool_.reset();
}
Expand All @@ -2086,7 +2085,7 @@ std::shared_ptr<IPayloadPool> DataWriterImpl::get_payload_pool()
// Prepare loans collection for plain types only
if (type_->is_plain(data_representation_))
{
loans_.reset(new LoanCollection(config));
loans_.reset(new LoanCollection(pool_config_));
}
}

Expand Down

0 comments on commit 00b127c

Please sign in to comment.