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

[core] Bugfix: descgate incorrectly locked with shared locks (master) #1462

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions ecal/core/src/ecal_descgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace eCAL

bool CDescGate::ApplyTopicDescription(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const QualityFlags description_quality_)
{
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_info_map.sync);
const std::unique_lock<std::mutex> lock(m_topic_info_map.sync);
m_topic_info_map.map->remove_deprecated();

const auto topic_info_it = m_topic_info_map.map->find(topic_name_);
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace eCAL
{
std::unordered_map<std::string, SDataTypeInformation> map;

const std::shared_lock<std::shared_timed_mutex> lock(m_topic_info_map.sync);
const std::lock_guard<std::mutex> lock(m_topic_info_map.sync);
m_topic_info_map.map->remove_deprecated();
map.reserve(m_topic_info_map.map->size());

Expand All @@ -209,7 +209,7 @@ namespace eCAL
{
topic_names_.clear();

const std::shared_lock<std::shared_timed_mutex> lock(m_topic_info_map.sync);
const std::lock_guard<std::mutex> lock(m_topic_info_map.sync);
m_topic_info_map.map->remove_deprecated();
topic_names_.reserve(m_topic_info_map.map->size());

Expand All @@ -223,7 +223,8 @@ namespace eCAL
{
if (topic_name_.empty()) return(false);

const std::shared_lock<std::shared_timed_mutex> lock(m_topic_info_map.sync);
const std::lock_guard<std::mutex> lock(m_topic_info_map.sync);
m_topic_info_map.map->remove_deprecated();
const auto topic_info_it = m_topic_info_map.map->find(topic_name_);

if (topic_info_it == m_topic_info_map.map->end()) return(false);
Expand All @@ -239,7 +240,7 @@ namespace eCAL
{
std::tuple<std::string, std::string> service_method_tuple = std::make_tuple(service_name_, method_name_);

const std::unique_lock<std::shared_timed_mutex> lock(m_service_info_map.sync);
const std::lock_guard<std::mutex> lock(m_service_info_map.sync);
m_service_info_map.map->remove_deprecated();

auto service_info_map_it = m_service_info_map.map->find(service_method_tuple);
Expand Down Expand Up @@ -275,7 +276,7 @@ namespace eCAL
{
std::map<std::tuple<std::string, std::string>, SServiceMethodInformation> map;

const std::shared_lock<std::shared_timed_mutex> lock(m_service_info_map.sync);
const std::lock_guard<std::mutex> lock(m_service_info_map.sync);
m_service_info_map.map->remove_deprecated();

for (const auto& service_info : (*m_service_info_map.map))
Expand All @@ -289,7 +290,7 @@ namespace eCAL
{
service_method_names_.clear();

const std::shared_lock<std::shared_timed_mutex> lock(m_service_info_map.sync);
const std::lock_guard<std::mutex> lock(m_service_info_map.sync);
m_service_info_map.map->remove_deprecated();
service_method_names_.reserve(m_service_info_map.map->size());

Expand All @@ -303,7 +304,8 @@ namespace eCAL
{
std::tuple<std::string, std::string> service_method_tuple = std::make_tuple(service_name_, method_name_);

const std::shared_lock<std::shared_timed_mutex> lock(m_service_info_map.sync);
const std::lock_guard<std::mutex> lock(m_service_info_map.sync);
m_service_info_map.map->remove_deprecated();
auto service_info_map_it = m_service_info_map.map->find(service_method_tuple);

if (service_info_map_it == m_service_info_map.map->end()) return false;
Expand All @@ -316,7 +318,8 @@ namespace eCAL
{
std::tuple<std::string, std::string> service_method_tuple = std::make_tuple(service_name_, method_name_);

const std::shared_lock<std::shared_timed_mutex> lock(m_service_info_map.sync);
const std::lock_guard<std::mutex> lock(m_service_info_map.sync);
m_service_info_map.map->remove_deprecated();
auto service_info_map_it = m_service_info_map.map->find(service_method_tuple);

if (service_info_map_it == m_service_info_map.map->end()) return false;
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/ecal_descgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace eCAL
map(std::make_unique<TopicInfoMap>(timeout_))
{
};
mutable std::shared_timed_mutex sync; //!< Mutex protecting the map
mutable std::mutex sync; //!< Mutex protecting the map
std::unique_ptr<TopicInfoMap> map; //!< Map containing information about each known topic
};
STopicInfoMap m_topic_info_map;
Expand All @@ -120,7 +120,7 @@ namespace eCAL
map(std::make_unique<ServiceMethodInfoMap>(timeout_))
{
};
mutable std::shared_timed_mutex sync; //!< Mutex protecting the map
mutable std::mutex sync; //!< Mutex protecting the map
std::unique_ptr<ServiceMethodInfoMap> map; //!< Map containing information about each known service
};
SServiceMethodInfoMap m_service_info_map;
Expand Down
Loading