Skip to content

Commit

Permalink
Refs #21082. Move datasharing pool initialization to RTPSWriter.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Jun 19, 2024
1 parent dcac228 commit 6207776
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,12 @@ ReturnCode_t DataWriterImpl::enable()
w_att.endpoint.data_sharing_configuration().kind() != DataSharingKind::OFF)
{
auto writer_pool = std::dynamic_pointer_cast<fastdds::rtps::WriterPool>(pool);
if (!writer_pool || !writer_pool->init_shared_memory(
writer, w_att.endpoint.data_sharing_configuration().shm_directory()))
if (!writer_pool || !writer_pool->is_initialized())
{
EPROSIMA_LOG_ERROR(DATA_WRITER, "Could not initialize DataSharing writer pool");
RTPSDomain::removeRTPSWriter(writer);
writer = nullptr;
}
else
{
for (auto it = history_->changesBegin(); it != history_->changesEnd(); ++it)
{
writer_pool->add_to_shared_history(*it);
}
}
}

if (writer == nullptr &&
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/rtps/writer/PersistentWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ PersistentWriter::PersistentWriter(
hist->m_isHistoryFull =
hist->m_att.maximumReservedCaches > 0 &&
static_cast<int32_t>(hist->m_changes.size()) == hist->m_att.maximumReservedCaches;

// Prepare the changes for datasharing if compatible
if (att.endpoint.data_sharing_configuration().kind() != dds::DataSharingKind::OFF)
{
auto pool = std::dynamic_pointer_cast<WriterPool>(hist->get_payload_pool());
assert(pool != nullptr);
for (auto change : hist->m_changes)
{
pool->add_to_shared_history(change);
}
}
}

PersistentWriter::~PersistentWriter()
Expand Down
10 changes: 10 additions & 0 deletions src/cpp/rtps/writer/RTPSWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <fastdds/rtps/writer/RTPSWriter.h>

#include <memory>
#include <mutex>

#include <fastdds/dds/log/Log.hpp>
Expand Down Expand Up @@ -84,6 +85,15 @@ void RTPSWriter::init(
fixed_payload_size_ = mp_history->m_att.payloadMaxSize;
}

if (att.endpoint.data_sharing_configuration().kind() != dds::OFF)
{
std::shared_ptr<WriterPool> pool = std::dynamic_pointer_cast<WriterPool>(mp_history->get_payload_pool());
if (!pool || !pool->init_shared_memory(this, att.endpoint.data_sharing_configuration().shm_directory()))
{
EPROSIMA_LOG_ERROR(RTPS_WRITER, "Could not initialize DataSharing writer pool");
}
}

mp_history->mp_writer = this;
mp_history->mp_mutex = &mp_mutex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class WriterPool : public DataSharingPayloadPool
return true;
}

bool is_initialized() const
{
return writer_guid_ != GUID_t::unknown();
}

void add_to_shared_history(
const CacheChange_t* /*cache_change*/)
{
Expand Down

0 comments on commit 6207776

Please sign in to comment.