Skip to content

Commit bdd319b

Browse files
juanlofer-eprosimaMiguelCompany
authored andcommitted
Protect PDPStatelessWriter attributes (#6100)
* Refs #23822. Protect PDPStatelessWriter attributes Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Refs #23822. Atomize matched_ attribute Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Refs #23822. Protect reader_data_filter_ attribute Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> --------- Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> (cherry picked from commit 6ca678b)
1 parent 64d4646 commit bdd319b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/cpp/rtps/builtin/discovery/participant/simple/PDPStatelessWriter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ PDPStatelessWriter::PDPStatelessWriter(
5555
bool PDPStatelessWriter::matched_reader_add_edp(
5656
const ReaderProxyData& data)
5757
{
58+
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
5859
bool ret = StatelessWriter::matched_reader_add_edp(data);
5960
if (ret)
6061
{
@@ -69,6 +70,7 @@ bool PDPStatelessWriter::matched_reader_add_edp(
6970
bool PDPStatelessWriter::matched_reader_remove(
7071
const GUID_t& reader_guid)
7172
{
73+
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
7274
bool ret = StatelessWriter::matched_reader_remove(reader_guid);
7375
if (ret)
7476
{
@@ -82,14 +84,15 @@ void PDPStatelessWriter::unsent_change_added_to_history(
8284
CacheChange_t* change,
8385
const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time)
8486
{
87+
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
8588
mark_all_readers_interested();
8689
StatelessWriter::unsent_change_added_to_history(change, max_blocking_time);
8790
}
8891

8992
void PDPStatelessWriter::set_initial_peers(
9093
const LocatorList& locator_list)
9194
{
92-
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
95+
std::lock_guard<std::mutex> guard(interested_readers_mutex_);
9396

9497
initial_peers_.push_back(locator_list);
9598
mp_RTPSParticipant->createSenderResources(initial_peers_);
@@ -106,6 +109,8 @@ bool PDPStatelessWriter::send_to_fixed_locators(
106109
const uint32_t& total_bytes,
107110
std::chrono::steady_clock::time_point& max_blocking_time_point) const
108111
{
112+
std::lock_guard<std::mutex> guard(interested_readers_mutex_);
113+
109114
bool ret = true;
110115

111116
if (should_reach_all_destinations_)
@@ -133,13 +138,15 @@ bool PDPStatelessWriter::is_relevant(
133138
const fastdds::rtps::CacheChange_t& /* change */,
134139
const fastdds::rtps::GUID_t& reader_guid) const
135140
{
141+
std::lock_guard<std::mutex> guard(interested_readers_mutex_);
136142
return interested_readers_.end() !=
137143
std::find(interested_readers_.begin(), interested_readers_.end(), reader_guid);
138144
}
139145

140146
void PDPStatelessWriter::mark_all_readers_interested()
141147
{
142148
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
149+
std::lock_guard<std::mutex> _guard(interested_readers_mutex_);
143150
should_reach_all_destinations_ = true;
144151
interested_readers_.clear();
145152
fixed_locators_.clear();
@@ -151,6 +158,7 @@ void PDPStatelessWriter::add_interested_reader(
151158
const GUID_t& reader_guid)
152159
{
153160
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
161+
std::lock_guard<std::mutex> _guard(interested_readers_mutex_);
154162
if (!should_reach_all_destinations_)
155163
{
156164
auto it = std::find(interested_readers_.begin(), interested_readers_.end(), reader_guid);
@@ -165,7 +173,7 @@ void PDPStatelessWriter::add_interested_reader(
165173
void PDPStatelessWriter::remove_interested_reader(
166174
const GUID_t& reader_guid)
167175
{
168-
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
176+
std::lock_guard<std::mutex> guard(interested_readers_mutex_);
169177
interested_readers_.remove(reader_guid);
170178
}
171179

src/cpp/rtps/builtin/discovery/participant/simple/PDPStatelessWriter.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_SIMPLE__PDPSTATELESSWRITER_HPP
2121

2222
#include <chrono>
23+
#include <mutex>
2324

2425
#include <fastdds/rtps/common/LocatorList.hpp>
2526
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
@@ -144,6 +145,8 @@ class PDPStatelessWriter : public StatelessWriter, private IReaderDataFilter
144145
mutable ResourceLimitedVector<GUID_t> interested_readers_;
145146
//! Whether we have set that all destinations are interested
146147
mutable bool should_reach_all_destinations_ = false;
148+
//! Mutex to protect attributes of this class
149+
mutable std::mutex interested_readers_mutex_;
147150

148151
};
149152

test/blackbox/common/RTPSWithRegistrationWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ class RTPSWithRegistrationWriter
673673
bool initialized_;
674674
std::mutex mutex_;
675675
std::condition_variable cv_;
676-
uint32_t matched_;
676+
std::atomic<uint32_t> matched_;
677677
eprosima::fastdds::rtps::EntityId_t custom_entity_id_ = eprosima::fastdds::rtps::c_EntityId_Unknown;
678678
type_support type_;
679679
std::shared_ptr<eprosima::fastdds::rtps::IPayloadPool> payload_pool_;

0 commit comments

Comments
 (0)