Skip to content

Commit

Permalink
_sync -> _mutex
Browse files Browse the repository at this point in the history
Constructor handling (code duplicates)
  • Loading branch information
rex-schilasky committed Dec 16, 2024
1 parent 443eb16 commit 4122a12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
12 changes: 6 additions & 6 deletions ecal/core/src/pubsub/ecal_pubgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace eCAL
if(!m_created) return;

// stop & destroy all remaining publisher
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
m_topic_name_publisher_map.clear();

m_created = false;
Expand All @@ -66,7 +66,7 @@ namespace eCAL
if(!m_created) return(false);

// register writer and multicast group
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
m_topic_name_publisher_map.emplace(std::pair<std::string, std::shared_ptr<CPublisherImpl>>(topic_name_, publisher_));

return(true);
Expand All @@ -77,7 +77,7 @@ namespace eCAL
if(!m_created) return(false);
bool ret_state = false;

const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::unique_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
auto res = m_topic_name_publisher_map.equal_range(topic_name_);
for(auto iter = res.first; iter != res.second; ++iter)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ namespace eCAL
#endif

// register subscriber
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
auto res = m_topic_name_publisher_map.equal_range(topic_name);
for(TopicNamePublisherMapT::const_iterator iter = res.first; iter != res.second; ++iter)
{
Expand All @@ -164,7 +164,7 @@ namespace eCAL
const SDataTypeInformation& topic_information = ecal_topic.tdatatype;

// unregister subscriber
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
auto res = m_topic_name_publisher_map.equal_range(topic_name);
for (TopicNamePublisherMapT::const_iterator iter = res.first; iter != res.second; ++iter)
{
Expand All @@ -177,7 +177,7 @@ namespace eCAL
if (!m_created) return;

// read reader registrations
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_sync);
const std::shared_lock<std::shared_timed_mutex> lock(m_topic_name_publisher_mutex);
for (const auto& iter : m_topic_name_publisher_map)
{
iter.second->GetRegistration(reg_sample_list_.push_back());
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/pubsub/ecal_pubgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace eCAL
static std::atomic<bool> m_created;

using TopicNamePublisherMapT = std::multimap<std::string, std::shared_ptr<CPublisherImpl>>;
std::shared_timed_mutex m_topic_name_publisher_sync;
std::shared_timed_mutex m_topic_name_publisher_mutex;
TopicNamePublisherMapT m_topic_name_publisher_map;
};
}
9 changes: 2 additions & 7 deletions ecal/core/src/pubsub/ecal_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ namespace eCAL
if(g_pubgate() != nullptr) g_pubgate()->Register(topic_name_, m_publisher_impl);
}

CPublisher::CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubEventIDCallbackT event_callback_, const Publisher::Configuration& config_)
CPublisher::CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubEventIDCallbackT event_callback_, const Publisher::Configuration& config_) :
CPublisher(topic_name_, data_type_info_, config_)
{
// create publisher implementation
m_publisher_impl = std::make_shared<CPublisherImpl>(data_type_info_, BuildWriterAttributes(topic_name_, config_, GetTransportLayerConfiguration(), GetRegistrationConfiguration()));

// register publisher
if (g_pubgate() != nullptr) g_pubgate()->Register(topic_name_, m_publisher_impl);

// add event callback for all current event types
m_publisher_impl->AddEventIDCallback(event_callback_);
}
Expand Down

0 comments on commit 4122a12

Please sign in to comment.