Skip to content

Commit 0725efa

Browse files
committed
Refs #21670: Apply Review 2
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent 5a88189 commit 0725efa

4 files changed

Lines changed: 18 additions & 27 deletions

File tree

ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,8 @@ class CommonParticipant : public core::IParticipant
153153
const fastdds::dds::PublicationBuiltinTopicData& info,
154154
bool& /*should_be_ignored*/) override;
155155

156-
//! Getter for GUID of the participant
157-
const fastdds::rtps::GUID_t& guid() const;
158-
159-
//! Setter for GUID of the participant
160-
void guid(
161-
const fastdds::rtps::GUID_t& guid);
162-
163156
protected:
164157

165-
//! GUID of the participant
166-
fastdds::rtps::GUID_t guid_;
167158
//! Shared pointer to the configuration of the participant
168159
const std::shared_ptr<SimpleParticipantConfiguration> configuration_;
169160
//! Shared pointer to the discovery database

ddspipe_participants/src/cpp/participant/dds/CommonParticipant.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ void CommonParticipant::init()
9696
{
9797
throw utils::InitializationException(STR_ENTRY << "Error enabling DDS Participant " << id() << ".");
9898
}
99-
100-
// Set the GUID of the participant in the DDS Listener
101-
static_cast<DDSListener*>(dds_participant_listener_.get())->guid(dds_participant_->guid());
10299
}
103100

104101
core::types::ParticipantId CommonParticipant::id() const noexcept
@@ -265,13 +262,13 @@ void CommonParticipant::DDSListener::on_participant_discovery(
265262
}
266263

267264
void CommonParticipant::DDSListener::on_data_reader_discovery(
268-
fastdds::dds::DomainParticipant*,
265+
fastdds::dds::DomainParticipant* participant,
269266
fastdds::rtps::ReaderDiscoveryStatus reason,
270267
const fastdds::dds::SubscriptionBuiltinTopicData& info,
271268
bool& /*should_be_ignored*/)
272269
{
273270
// If reader is from other participant, store it in discovery database
274-
if (detail::come_from_same_participant_(info.guid, guid()))
271+
if (detail::come_from_same_participant_(info.guid, participant->guid()))
275272
{
276273
// Come from this participant, do nothing
277274
return;
@@ -315,13 +312,13 @@ void CommonParticipant::DDSListener::on_data_reader_discovery(
315312
}
316313

317314
void CommonParticipant::DDSListener::on_data_writer_discovery(
318-
fastdds::dds::DomainParticipant*,
315+
fastdds::dds::DomainParticipant* participant,
319316
fastdds::rtps::WriterDiscoveryStatus reason,
320317
const fastdds::dds::PublicationBuiltinTopicData& info,
321318
bool& /*should_be_ignored*/)
322319
{
323320
// If writer is from other participant, store it in discovery database
324-
if (detail::come_from_same_participant_(info.guid, guid()))
321+
if (detail::come_from_same_participant_(info.guid, participant->guid()))
325322
{
326323
// Come from this participant, do nothing
327324
return;
@@ -364,17 +361,6 @@ void CommonParticipant::DDSListener::on_data_writer_discovery(
364361
}
365362
}
366363

367-
const fastdds::rtps::GUID_t& CommonParticipant::DDSListener::guid() const
368-
{
369-
return guid_;
370-
}
371-
372-
void CommonParticipant::DDSListener::guid(
373-
const fastdds::rtps::GUID_t& guid)
374-
{
375-
guid_ = guid;
376-
}
377-
378364
CommonParticipant::CommonParticipant(
379365
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
380366
const std::shared_ptr<core::PayloadPool>& payload_pool,

ddspipe_participants/src/cpp/reader/dds/CommonReader.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ void CommonReader::init()
8686
participant_id_ << " in topic " << topic_ << ".");
8787
}
8888

89+
// Subscriber is created with autoenable set to false, so we need to enable the reader manually.
90+
// This is done just to ensure that the reader is not registered before any other method modifying the reader pointer
91+
// is called, opening a window for potential data races. Although Fast DDS ensures that this cannot happen, this
92+
// procedure protects against future bad practices introducing the aforementioned data races.
93+
if (fastdds::dds::RETCODE_OK != reader_->enable())
94+
{
95+
dds_subscriber_->delete_datareader(reader_);
96+
throw utils::InitializationException(
97+
utils::Formatter() << "Error enabling DataReader for Participant " <<
98+
participant_id_ << " in topic " << topic_ << ".");
99+
}
100+
89101
}
90102

91103
void CommonReader::on_data_available(
@@ -221,6 +233,7 @@ fastdds::dds::SubscriberQos CommonReader::reckon_subscriber_qos_() const
221233
{
222234
qos.partition().push_back("*");
223235
}
236+
qos.entity_factory().autoenable_created_entities = false;
224237
return qos;
225238
}
226239

ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void CommonReader::internal_entities_creation_(
107107
// Create CommonReader
108108
// Listener must be set in creation as no callbacks should be missed
109109
// It is safe to do so here as object is already created and callbacks do not require anything set in this method
110+
// Also, no data races can ocurr as no callback will be called until this reader is registered
110111
rtps_reader_ = fastdds::rtps::RTPSDomain::createRTPSReader(
111112
rtps_participant_,
112113
non_const_reader_attributes,

0 commit comments

Comments
 (0)