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

Avoid unnecessary sets of GUID_t #586

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "fastdds/dds/core/status/BaseStatus.hpp"
#include "fastdds/dds/core/status/DeadlineMissedStatus.hpp"
#include "fastdds/dds/core/status/PublicationMatchedStatus.hpp"
#include "fastdds/dds/publisher/DataWriter.hpp"
#include "fastdds/dds/publisher/DataWriterListener.hpp"
#include "fastdds/dds/topic/Topic.hpp"
Expand Down Expand Up @@ -69,20 +68,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds
}

// DataWriterListener implementation
RMW_FASTRTPS_SHARED_CPP_PUBLIC
void
on_publication_matched(
eprosima::fastdds::dds::DataWriter * /* writer */,
const eprosima::fastdds::dds::PublicationMatchedStatus & info) final
{
std::lock_guard<std::mutex> lock(internalMutex_);
if (info.current_count_change == 1) {
subscriptions_.insert(eprosima::fastrtps::rtps::iHandle2GUID(info.last_subscription_handle));
} else if (info.current_count_change == -1) {
subscriptions_.erase(eprosima::fastrtps::rtps::iHandle2GUID(info.last_subscription_handle));
}
}

RMW_FASTRTPS_SHARED_CPP_PUBLIC
void
on_offered_deadline_missed(
Expand Down Expand Up @@ -116,12 +101,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds
takeNextEvent(rmw_event_type_t event_type, void * event_info) final;

// PubListener API
size_t subscriptionCount()
{
std::lock_guard<std::mutex> lock(internalMutex_);
return subscriptions_.size();
}

void
attachCondition(std::mutex * conditionMutex, std::condition_variable * conditionVariable)
{
Expand All @@ -141,9 +120,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds
private:
mutable std::mutex internalMutex_;

std::set<eprosima::fastrtps::rtps::GUID_t> subscriptions_
RCPPUTILS_TSA_GUARDED_BY(internalMutex_);

std::atomic_bool deadline_changes_;
eprosima::fastdds::dds::OfferedDeadlineMissedStatus offered_deadline_missed_status_
RCPPUTILS_TSA_GUARDED_BY(internalMutex_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "fastdds/dds/core/status/DeadlineMissedStatus.hpp"
#include "fastdds/dds/core/status/LivelinessChangedStatus.hpp"
#include "fastdds/dds/core/status/SubscriptionMatchedStatus.hpp"
#include "fastdds/dds/subscriber/DataReader.hpp"
#include "fastdds/dds/subscriber/DataReaderListener.hpp"
#include "fastdds/dds/topic/TypeSupport.hpp"
Expand Down Expand Up @@ -89,14 +88,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds
eprosima::fastdds::dds::DataReader * reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus & info) final
{
{
std::lock_guard<std::mutex> lock(internalMutex_);
if (info.current_count_change == 1) {
publishers_.insert(eprosima::fastrtps::rtps::iHandle2GUID(info.last_publication_handle));
} else if (info.current_count_change == -1) {
publishers_.erase(eprosima::fastrtps::rtps::iHandle2GUID(info.last_publication_handle));
}
}
update_has_data(reader);
}

Expand Down Expand Up @@ -188,12 +179,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds
data_.store(has_data, std::memory_order_relaxed);
}

size_t publisherCount()
{
std::lock_guard<std::mutex> lock(internalMutex_);
return publishers_.size();
}

// Provide handlers to perform an action when a
// new event from this listener has ocurred
void
Expand Down Expand Up @@ -242,8 +227,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds
std::mutex * conditionMutex_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_);
std::condition_variable * conditionVariable_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_);

std::set<eprosima::fastrtps::rtps::GUID_t> publishers_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_);

rmw_event_callback_t on_new_message_cb_{nullptr};
std::mutex on_new_message_m_;
size_t qos_depth_;
Expand Down
6 changes: 4 additions & 2 deletions rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"

#include "fastdds/dds/core/status/PublicationMatchedStatus.hpp"
#include "fastdds/dds/publisher/DataWriter.hpp"
#include "fastdds/dds/publisher/qos/DataWriterQos.hpp"

Expand Down Expand Up @@ -93,8 +94,9 @@ __rmw_publisher_count_matched_subscriptions(
size_t * subscription_count)
{
auto info = static_cast<CustomPublisherInfo *>(publisher->data);

*subscription_count = info->listener_->subscriptionCount();
eprosima::fastdds::dds::PublicationMatchedStatus status{};
info->data_writer_->get_publication_matched_status(status);
*subscription_count = status.current_count;

return RMW_RET_OK;
}
Expand Down
6 changes: 4 additions & 2 deletions rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "rmw/error_handling.h"
#include "rmw/rmw.h"

#include "fastdds/dds/core/status/SubscriptionMatchedStatus.hpp"
#include "fastdds/dds/subscriber/DataReader.hpp"
#include "fastdds/dds/subscriber/qos/DataReaderQos.hpp"

Expand Down Expand Up @@ -87,8 +88,9 @@ __rmw_subscription_count_matched_publishers(
size_t * publisher_count)
{
auto info = static_cast<CustomSubscriberInfo *>(subscription->data);

*publisher_count = info->listener_->publisherCount();
eprosima::fastdds::dds::SubscriptionMatchedStatus status{};
info->data_reader_->get_subscription_matched_status(status);
*publisher_count = status.current_count;

return RMW_RET_OK;
}
Expand Down