Skip to content

Commit

Permalink
Protection of discovered_names and discovered_namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed May 28, 2019
1 parent 66d9128 commit 38fe220
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "fastrtps/participant/Participant.h"
#include "fastrtps/participant/ParticipantListener.h"

#include "rcpputils/thread_safety_annotations.hpp"
#include "rcutils/logging_macros.h"

#include "rmw/impl/cpp/key_value.hpp"
Expand Down Expand Up @@ -68,6 +69,7 @@ class ParticipantListener : public eprosima::fastrtps::ParticipantListener
return;
}

std::lock_guard<std::mutex> guard(names_mutex_);
if (eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT == info.status) {
// ignore already known GUIDs
if (discovered_names.find(info.info.m_guid) == discovered_names.end()) {
Expand Down Expand Up @@ -115,6 +117,7 @@ class ParticipantListener : public eprosima::fastrtps::ParticipantListener

std::vector<std::string> get_discovered_names() const
{
std::lock_guard<std::mutex> guard(names_mutex_);
std::vector<std::string> names(discovered_names.size());
size_t i = 0;
for (auto it : discovered_names) {
Expand All @@ -125,6 +128,7 @@ class ParticipantListener : public eprosima::fastrtps::ParticipantListener

std::vector<std::string> get_discovered_namespaces() const
{
std::lock_guard<std::mutex> guard(names_mutex_);
std::vector<std::string> namespaces(discovered_namespaces.size());
size_t i = 0;
for (auto it : discovered_namespaces) {
Expand Down Expand Up @@ -179,8 +183,10 @@ class ParticipantListener : public eprosima::fastrtps::ParticipantListener
}
}

std::map<eprosima::fastrtps::rtps::GUID_t, std::string> discovered_names;
std::map<eprosima::fastrtps::rtps::GUID_t, std::string> discovered_namespaces;
using guid_map_t = std::map<eprosima::fastrtps::rtps::GUID_t, std::string>;
mutable std::mutex names_mutex_;
guid_map_t discovered_names RCPPUTILS_TSA_GUARDED_BY(names_mutex_);
guid_map_t discovered_namespaces RCPPUTILS_TSA_GUARDED_BY(names_mutex_);
LockedObject<TopicCache> reader_topic_cache;
LockedObject<TopicCache> writer_topic_cache;
rmw_guard_condition_t * graph_guard_condition_;
Expand Down

0 comments on commit 38fe220

Please sign in to comment.