Add exit to graph manager thread

This commit is contained in:
Antonio cuadros
2021-07-16 13:54:46 +02:00
parent 37566d1c74
commit 39d8ed0ba2
2 changed files with 17 additions and 2 deletions
@@ -80,7 +80,16 @@ public:
/**
* @brief Default destructor.
*/
~GraphManager() = default;
~GraphManager()
{
exit = true;
cv_.notify_one();
if (microros_graph_publisher_.joinable())
{
microros_graph_publisher_.join();
}
}
/**
* @brief Implementation of the notification logic that updates the micro-ROS graph.
@@ -298,6 +307,7 @@ private:
std::string& node_name,
std::string& node_namespace);
bool exit = false;
eprosima::fastdds::dds::DomainId_t domain_id_;
bool graph_changed_;
bool display_on_change_;
@@ -137,10 +137,15 @@ inline void GraphManager::publish_microros_graph()
std::unique_lock<std::mutex> lock(mtx_);
cv_.wait(lock, [this]()
{
return this->graph_changed_;
return this->graph_changed_ || exit;
});
}
if (exit)
{
break;
}
if (display_on_change_)
{
std::cout << "Updated uros Graph: graph changed" << std::endl;