Allow removing a waitable (#597)
This commit is contained in:
parent
3af8d2cfed
commit
9c25ba9a4a
5 changed files with 47 additions and 0 deletions
|
@ -112,6 +112,10 @@ protected:
|
||||||
void
|
void
|
||||||
add_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr);
|
add_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr);
|
||||||
|
|
||||||
|
RCLCPP_PUBLIC
|
||||||
|
void
|
||||||
|
remove_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept;
|
||||||
|
|
||||||
CallbackGroupType type_;
|
CallbackGroupType type_;
|
||||||
// Mutex to protect the subsequent vectors of pointers.
|
// Mutex to protect the subsequent vectors of pointers.
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
|
|
|
@ -48,6 +48,13 @@ public:
|
||||||
rclcpp::Waitable::SharedPtr waitable_base_ptr,
|
rclcpp::Waitable::SharedPtr waitable_base_ptr,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group);
|
rclcpp::callback_group::CallbackGroup::SharedPtr group);
|
||||||
|
|
||||||
|
RCLCPP_PUBLIC
|
||||||
|
virtual
|
||||||
|
void
|
||||||
|
remove_waitable(
|
||||||
|
rclcpp::Waitable::SharedPtr waitable_ptr,
|
||||||
|
rclcpp::callback_group::CallbackGroup::SharedPtr group) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RCLCPP_DISABLE_COPY(NodeWaitables)
|
RCLCPP_DISABLE_COPY(NodeWaitables)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,14 @@ public:
|
||||||
add_waitable(
|
add_waitable(
|
||||||
rclcpp::Waitable::SharedPtr waitable_ptr,
|
rclcpp::Waitable::SharedPtr waitable_ptr,
|
||||||
rclcpp::callback_group::CallbackGroup::SharedPtr group) = 0;
|
rclcpp::callback_group::CallbackGroup::SharedPtr group) = 0;
|
||||||
|
|
||||||
|
/// \note this function should not throw because it may be called in destructors
|
||||||
|
RCLCPP_PUBLIC
|
||||||
|
virtual
|
||||||
|
void
|
||||||
|
remove_waitable(
|
||||||
|
rclcpp::Waitable::SharedPtr waitable_ptr,
|
||||||
|
rclcpp::callback_group::CallbackGroup::SharedPtr group) noexcept = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace node_interfaces
|
} // namespace node_interfaces
|
||||||
|
|
|
@ -105,3 +105,16 @@ CallbackGroup::add_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr)
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
waitable_ptrs_.push_back(waitable_ptr);
|
waitable_ptrs_.push_back(waitable_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CallbackGroup::remove_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
for (auto iter = waitable_ptrs_.begin(); iter != waitable_ptrs_.end(); ++iter) {
|
||||||
|
const auto shared_ptr = iter->lock();
|
||||||
|
if (shared_ptr.get() == waitable_ptr.get()) {
|
||||||
|
waitable_ptrs_.erase(iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -51,3 +51,18 @@ NodeWaitables::add_waitable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NodeWaitables::remove_waitable(
|
||||||
|
rclcpp::Waitable::SharedPtr waitable_ptr,
|
||||||
|
rclcpp::callback_group::CallbackGroup::SharedPtr group) noexcept
|
||||||
|
{
|
||||||
|
if (group) {
|
||||||
|
if (!node_base_->callback_group_in_node(group)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
group->remove_waitable(waitable_ptr);
|
||||||
|
} else {
|
||||||
|
node_base_->get_default_callback_group()->remove_waitable(waitable_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue