@@ -303,17 +303,22 @@ void DdsPipe::discovered_endpoint_nts_(
303303 // update the track of the topic to
304304 // add the partition in the reader if it is in the filter
305305
306- const auto bridge_it = bridges_.find (utils::Heritable<DdsTopic>::make_heritable (endpoint.topic ));
307- // add the specific partition of the endpoint in the bridges topic.
308- if (bridge_it != bridges_.end ())
306+ // update partitions under bridges_mutex_
309307 {
310- std::ostringstream guid_ss;
311- guid_ss << endpoint.guid ;
308+ std::lock_guard<std::mutex> lock (bridges_mutex_);
312309
313- const auto part_it = endpoint.specific_partitions .find (guid_ss.str ());
314- if (part_it != endpoint.specific_partitions .end ())
310+ const auto bridge_it = bridges_.find (utils::Heritable<DdsTopic>::make_heritable (endpoint.topic ));
311+ // add the specific partition of the endpoint in the bridges topic.
312+ if (bridge_it != bridges_.end ())
315313 {
316- bridge_it->second ->add_partition_to_topic (guid_ss.str (), part_it->second );
314+ std::ostringstream guid_ss;
315+ guid_ss << endpoint.guid ;
316+
317+ const auto part_it = endpoint.specific_partitions .find (guid_ss.str ());
318+ if (part_it != endpoint.specific_partitions .end ())
319+ {
320+ bridge_it->second ->add_partition_to_topic (guid_ss.str (), part_it->second );
321+ }
317322 }
318323 }
319324
@@ -648,6 +653,9 @@ void DdsPipe::update_content_filter(
648653void DdsPipe::update_filter (
649654 const std::set<std::string> filter_partition_set)
650655{
656+ // Avoid possible datarace with partitions filter
657+ std::lock_guard<std::mutex> lock (bridges_mutex_);
658+
651659 filter_partition_ = std::move (filter_partition_set);
652660}
653661
0 commit comments