Skip to content

Commit d4be840

Browse files
authored
Synchronise predicate (#160)
* ensure synchronised access to our predicate Signed-off-by: Aaron <[email protected]> * release lock before signalling Signed-off-by: Aaron <[email protected]> Signed-off-by: Aaron <[email protected]>
1 parent da7fb68 commit d4be840

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

micro_ros_agent/src/agent/graph_manager/graph_manager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id)
126126
// Set graph cache on change callback function
127127
graphCache_.set_on_change_callback([this]()
128128
{
129-
std::unique_lock<std::mutex> lock(this->mtx_);
130-
this->graph_changed_ = true;
129+
{
130+
std::unique_lock<std::mutex> lock(this->mtx_);
131+
this->graph_changed_ = true;
132+
}
131133
this->cv_.notify_one();
132134
});
133135

@@ -144,14 +146,14 @@ inline void GraphManager::publish_microros_graph()
144146
{
145147
return this->graph_changed_;
146148
});
149+
graph_changed_ = false;
147150
}
148151

149152
if (display_on_change_)
150153
{
151154
std::cout << "Updated uros Graph: graph changed" << std::endl;
152155
std::cout << graphCache_ << std::endl;
153156
}
154-
graph_changed_ = false;
155157

156158
micro_ros_msgs::msg::Graph graph_message;
157159

0 commit comments

Comments
 (0)