Skip to content

Commit

Permalink
Refs #21186: Apply rev suggestions (2)
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <[email protected]>
  • Loading branch information
JesusPoderoso committed Jul 19, 2024
1 parent 78bd1a6 commit 4c5fa90
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions examples/cpp/topic_instances/SubscriberApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ void SubscriberApp::on_data_available(
// Print the shape
std::cout << shape_.color() << " Shape with size " << shape_.shapesize()
<< " at X:" << shape_.x() << ", Y:" << shape_.y() << " RECEIVED" << std::endl;

// Check if the execution should be stopped
if ((samples_ > 0) && instances_received_all_samples())
{
stop_receiving_samples_.store(true);
cv_.notify_all();
}
}
else if (info.instance_state == NOT_ALIVE_DISPOSED_INSTANCE_STATE)
{
Expand All @@ -179,13 +186,6 @@ void SubscriberApp::on_data_available(
{
std::cout << shape_.color() << " Shape has been disposed by all publishers" << std::endl;
}

// Check if the execution should be stopped
if ((samples_ > 0) && instances_received_all_samples())
{
stop_receiving_samples_.store(true);
cv_.notify_all();
}
}
}

Expand All @@ -195,15 +195,15 @@ void SubscriberApp::run()
std::unique_lock<std::mutex> lock_(mutex_);
cv_.wait(lock_, [&]
{
return stop_receiving_samples_.load();
return stop_receiving_samples_.load() || is_stopped();
});
}
// Wait for period or stop event
{
std::unique_lock<std::mutex> timeout_lock(mutex_);
cv_.wait_for(timeout_lock, std::chrono::milliseconds(50u), [&]()
{
return instances_disposed();
return instances_disposed() || is_stopped();
});
}
stop();
Expand Down

0 comments on commit 4c5fa90

Please sign in to comment.