Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing data race on custom_participant_info. #283

Merged
merged 1 commit into from
May 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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