Skip to content

Commit

Permalink
[core] Bugfix: descgate incorrectly locked with shared locks. (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Mar 14, 2024
1 parent 223b543 commit d72bbc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions ecal/core/src/ecal_descgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 @@ -190,7 +190,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 @@ -205,7 +205,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 @@ -219,7 +219,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 @@ -235,7 +236,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 @@ -271,7 +272,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 @@ -285,7 +286,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 @@ -299,7 +300,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 @@ -312,7 +314,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 @@ -106,7 +106,7 @@ namespace eCAL
map(new 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 @@ -119,7 +119,7 @@ namespace eCAL
map(new 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

0 comments on commit d72bbc0

Please sign in to comment.