Skip to content

Commit

Permalink
#Refs: 21302: Fix deadlock caused by Subscriber destructor
Browse files Browse the repository at this point in the history
Signed-off-by: Carlosespicur <[email protected]>
  • Loading branch information
Carlosespicur committed Jul 31, 2024
1 parent 23d2355 commit a885a58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
11 changes: 9 additions & 2 deletions test/dds/communication/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <csignal>
#include <thread>

#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
Expand Down Expand Up @@ -185,10 +186,10 @@ bool Subscriber::init(
// CREATE THE READER
if (max_messages > 0)
{
listener_.set_max_messages(max_messages);
listener.set_max_messages(max_messages);
}
eprosima::fastdds::dds::DataReaderQos rqos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT;
reader_ = subscriber_->create_datareader(topic_, rqos, &listener_);
reader_ = subscriber_->create_datareader(topic_, rqos, &listener);

if (reader_ == nullptr)
{
Expand Down Expand Up @@ -362,5 +363,11 @@ int main(
sub.init(samples, seed % 230);
sub.run(samples);

// Wait until all datawriters are unmatched
while (sub.listener.get_matched() > 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

return 0;
}
40 changes: 21 additions & 19 deletions test/dds/communication/Subscriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ class Subscriber

//! Trigger the end of execution
static void stop();

private:

eprosima::fastdds::dds::DomainParticipant* participant_;

eprosima::fastdds::dds::Subscriber* subscriber_;

eprosima::fastdds::dds::Topic* topic_;

eprosima::fastdds::dds::DataReader* reader_;

eprosima::fastdds::dds::TypeSupport type_;

/**
* Class handling discovery and dataflow events
*/
class SubListener : public eprosima::fastdds::dds::DataReaderListener
{
public:
Expand Down Expand Up @@ -99,7 +83,11 @@ class Subscriber
void on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;


uint32_t get_matched()
{
return matched_;
}
private:

Communication comm_;
Expand All @@ -116,9 +104,23 @@ class Subscriber
//! Avoids race conditions in callback execution
std::mutex mutex_;
std::condition_variable cv_;
}
} listener;

listener_;
private:

eprosima::fastdds::dds::DomainParticipant* participant_;

eprosima::fastdds::dds::Subscriber* subscriber_;

eprosima::fastdds::dds::Topic* topic_;

eprosima::fastdds::dds::DataReader* reader_;

eprosima::fastdds::dds::TypeSupport type_;

/**
* Class handling discovery and dataflow events
*/

//! Member used for control flow purposes
static std::atomic<bool> stop_;
Expand Down

0 comments on commit a885a58

Please sign in to comment.