Skip to content

Commit

Permalink
Fix and refactor EDPSimple destructor (#2337)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
(cherry picked from commit e13251f)

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
mergify[bot] and MiguelCompany authored Dec 3, 2021
1 parent c5596d3 commit 1f4a4b9
Showing 1 changed file with 35 additions and 66 deletions.
101 changes: 35 additions & 66 deletions src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ static const Duration_t edp_heartbeat_response_delay{0, 10 * 1000}; // 10 millis
static const int32_t edp_reader_initial_reserved_caches = 1;
static const int32_t edp_writer_initial_reserved_caches = 20;

static void delete_reader(
RTPSParticipantImpl* participant,
std::pair<StatefulReader*, ReaderHistory*>& reader_pair,
std::shared_ptr<ITopicPayloadPool>& pool)
{
if (nullptr != reader_pair.first)
{
participant->deleteUserEndpoint(reader_pair.first);
EDPUtils::release_payload_pool(pool, reader_pair.second->m_att, true);
delete(reader_pair.second);
}
}

static void delete_writer(
RTPSParticipantImpl* participant,
std::pair<StatefulWriter*, WriterHistory*>& writer_pair,
std::shared_ptr<ITopicPayloadPool>& pool)
{
if (nullptr != writer_pair.first)
{
participant->deleteUserEndpoint(writer_pair.first);
EDPUtils::release_payload_pool(pool, writer_pair.second->m_att, false);
delete(writer_pair.second);
}
}

EDPSimple::EDPSimple(
PDP* p,
RTPSParticipantImpl* part)
Expand All @@ -79,75 +105,18 @@ EDPSimple::EDPSimple(
EDPSimple::~EDPSimple()
{
#if HAVE_SECURITY
if (this->publications_secure_reader_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(publications_secure_reader_.first);
EDPUtils::release_payload_pool(sec_pub_reader_payload_pool_, publications_secure_writer_.second->m_att, true);
delete(publications_secure_reader_.second);
}

if (this->subscriptions_secure_reader_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_secure_reader_.first);
EDPUtils::release_payload_pool(sec_sub_reader_payload_pool_, subscriptions_secure_reader_.second->m_att, true);
delete(subscriptions_secure_reader_.second);
}
delete_reader(mp_RTPSParticipant, publications_secure_reader_, sec_pub_reader_payload_pool_);
delete_reader(mp_RTPSParticipant, subscriptions_secure_reader_, sec_sub_reader_payload_pool_);

if (this->publications_secure_writer_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(publications_secure_writer_.first);
EDPUtils::release_payload_pool(sec_pub_writer_payload_pool_, publications_secure_writer_.second->m_att, false);
delete(publications_secure_writer_.second);
}

if (this->subscriptions_secure_writer_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_secure_writer_.first);
EDPUtils::release_payload_pool(sec_sub_writer_payload_pool_, subscriptions_secure_writer_.second->m_att, true);
delete(subscriptions_secure_writer_.second);
}
delete_writer(mp_RTPSParticipant, publications_secure_writer_, sec_pub_writer_payload_pool_);
delete_writer(mp_RTPSParticipant, subscriptions_secure_writer_, sec_sub_writer_payload_pool_);
#endif // if HAVE_SECURITY

if (this->publications_reader_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(publications_reader_.first);
// This payload is created outside the constructor, so it could not be created
if (nullptr != pub_reader_payload_pool_)
{
EDPUtils::release_payload_pool(pub_reader_payload_pool_, publications_reader_.second->m_att, true);
}
delete(publications_reader_.second);
}
if (this->subscriptions_reader_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_reader_.first);
// This payload is created outside the constructor, so it could not be created
if (nullptr != sub_reader_payload_pool_)
{
EDPUtils::release_payload_pool(sub_reader_payload_pool_, subscriptions_reader_.second->m_att, true);
}
delete(subscriptions_reader_.second);
}
if (this->publications_writer_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(publications_writer_.first);
// This payload is created outside the constructor, so it could not be created
if (nullptr != pub_writer_payload_pool_)
{
EDPUtils::release_payload_pool(pub_writer_payload_pool_, publications_writer_.second->m_att, false);
}
delete(publications_writer_.second);
}
if (this->subscriptions_writer_.first != nullptr)
{
this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_writer_.first);
// This payload is created outside the constructor, so it could not be created
if (nullptr != sub_writer_payload_pool_)
{
EDPUtils::release_payload_pool(sub_writer_payload_pool_, subscriptions_writer_.second->m_att, false);
}
delete(subscriptions_writer_.second);
}
delete_reader(mp_RTPSParticipant, publications_reader_, pub_reader_payload_pool_);
delete_reader(mp_RTPSParticipant, subscriptions_reader_, sub_reader_payload_pool_);

delete_writer(mp_RTPSParticipant, publications_writer_, pub_writer_payload_pool_);
delete_writer(mp_RTPSParticipant, subscriptions_writer_, sub_writer_payload_pool_);

if (nullptr != publications_listener_)
{
Expand Down

0 comments on commit 1f4a4b9

Please sign in to comment.