ROS 2 rclcpp + rcl - kilted
kilted
ROS 2 C++ Client Library with ROS Client Library
|
WaitSet policy that provides thread-safe synchronization for the wait set. More...
#include <rclcpp/wait_set_policies/thread_safe_synchronization.hpp>
Protected Member Functions | |
ThreadSafeSynchronization (rclcpp::Context::SharedPtr context) | |
const std::array< std::shared_ptr< rclcpp::GuardCondition >, 1 > & | get_extra_guard_conditions () |
Return any "extra" guard conditions needed to implement the synchronization policy. More... | |
void | interrupt_waiting_wait_set () |
Interrupt any waiting wait set. More... | |
void | sync_add_subscription (std::shared_ptr< rclcpp::SubscriptionBase > &&subscription, const rclcpp::SubscriptionWaitSetMask &mask, std::function< void(std::shared_ptr< rclcpp::SubscriptionBase > &&, const rclcpp::SubscriptionWaitSetMask &) > add_subscription_function) |
Add subscription. | |
void | sync_remove_subscription (std::shared_ptr< rclcpp::SubscriptionBase > &&subscription, const rclcpp::SubscriptionWaitSetMask &mask, std::function< void(std::shared_ptr< rclcpp::SubscriptionBase > &&, const rclcpp::SubscriptionWaitSetMask &) > remove_subscription_function) |
Remove guard condition. | |
void | sync_add_guard_condition (std::shared_ptr< rclcpp::GuardCondition > &&guard_condition, std::function< void(std::shared_ptr< rclcpp::GuardCondition > &&)> add_guard_condition_function) |
Add guard condition. | |
void | sync_remove_guard_condition (std::shared_ptr< rclcpp::GuardCondition > &&guard_condition, std::function< void(std::shared_ptr< rclcpp::GuardCondition > &&)> remove_guard_condition_function) |
Remove guard condition. | |
void | sync_add_timer (std::shared_ptr< rclcpp::TimerBase > &&timer, std::function< void(std::shared_ptr< rclcpp::TimerBase > &&)> add_timer_function) |
Add timer. | |
void | sync_remove_timer (std::shared_ptr< rclcpp::TimerBase > &&timer, std::function< void(std::shared_ptr< rclcpp::TimerBase > &&)> remove_timer_function) |
Remove timer. | |
void | sync_add_client (std::shared_ptr< rclcpp::ClientBase > &&client, std::function< void(std::shared_ptr< rclcpp::ClientBase > &&)> add_client_function) |
Add client. | |
void | sync_remove_client (std::shared_ptr< rclcpp::ClientBase > &&client, std::function< void(std::shared_ptr< rclcpp::ClientBase > &&)> remove_client_function) |
Remove client. | |
void | sync_add_service (std::shared_ptr< rclcpp::ServiceBase > &&service, std::function< void(std::shared_ptr< rclcpp::ServiceBase > &&)> add_service_function) |
Add service. | |
void | sync_remove_service (std::shared_ptr< rclcpp::ServiceBase > &&service, std::function< void(std::shared_ptr< rclcpp::ServiceBase > &&)> remove_service_function) |
Remove service. | |
void | sync_add_waitable (std::shared_ptr< rclcpp::Waitable > &&waitable, std::shared_ptr< void > &&associated_entity, std::function< void(std::shared_ptr< rclcpp::Waitable > &&, std::shared_ptr< void > &&) > add_waitable_function) |
Add waitable. | |
void | sync_remove_waitable (std::shared_ptr< rclcpp::Waitable > &&waitable, std::function< void(std::shared_ptr< rclcpp::Waitable > &&)> remove_waitable_function) |
Remove waitable. | |
void | sync_prune_deleted_entities (std::function< void()> prune_deleted_entities_function) |
Prune deleted entities. | |
template<class WaitResultT > | |
WaitResultT | sync_wait (std::chrono::nanoseconds time_to_wait_ns, std::function< void()> rebuild_rcl_wait_set, std::function< rcl_wait_set_t &()> get_rcl_wait_set, std::function< WaitResultT(WaitResultKind wait_result_kind)> create_wait_result) |
Implements wait. | |
void | sync_wait_result_acquire () |
void | sync_wait_result_release () |
![]() | |
std::function< bool()> | create_loop_predicate (std::chrono::nanoseconds time_to_wait_ns, std::chrono::steady_clock::time_point start) |
std::chrono::nanoseconds | calculate_time_left_to_wait (std::chrono::nanoseconds original_time_to_wait_ns, std::chrono::steady_clock::time_point start) |
Protected Attributes | |
std::array< std::shared_ptr< rclcpp::GuardCondition >, 1 > | extra_guard_conditions_ |
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock | wprw_lock_ |
WaitSet policy that provides thread-safe synchronization for the wait set.
This class uses a "write-preferring RW lock" so that adding items to, and removing items from, the wait set will take priority over reading, i.e. waiting. This is done since add and remove calls will interrupt the wait set anyways so it is wasteful to do "fair" locking when there are many add/remove operations queued up.
There are some things to consider about the thread-safety provided by this policy. There are two categories of activities, reading and writing activities. The writing activities include all of the add and remove methods, as well as the prune_deleted_entities() method. The reading methods include the wait() method and keeping a WaitResult in scope. The reading and writing activities will not be run at the same time, and one will block the other. Therefore, if you are holding a WaitResult in scope, and try to add or remove an entity at the same time, they will block each other. The write activities will try to interrupt the wait() method by triggering a guard condition, but they have no way of causing the WaitResult to release its lock.
Definition at line 67 of file thread_safe_synchronization.hpp.
|
inlineprotected |
Return any "extra" guard conditions needed to implement the synchronization policy.
This policy has one guard condition which is used to interrupt the wait set when adding and removing entities.
Definition at line 82 of file thread_safe_synchronization.hpp.
|
inlineprotected |
Interrupt any waiting wait set.
Used to interrupt the wait set when adding or removing items.
Definition at line 92 of file thread_safe_synchronization.hpp.