ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Classes | Public Member Functions | List of all members
rclcpp::ClockConditionalVariable Class Reference

#include <rclcpp/clock.hpp>

Classes

class  Impl
 

Public Member Functions

RCLCPP_PUBLIC ClockConditionalVariable (const rclcpp::Clock::SharedPtr &clock, rclcpp::Context::SharedPtr context=rclcpp::contexts::get_global_default_context())
 
RCLCPP_PUBLIC bool wait_until (std::unique_lock< std::mutex > &lock, rclcpp::Time until, const std::function< bool()> &pred)
 
RCLCPP_PUBLIC void notify_one ()
 
RCLCPP_PUBLIC std::mutex & mutex ()
 

Detailed Description

A synchronization primitive, similar to std::conditional_variable, that works with the rclcpp::Clock.

For more information on the API see https://en.cppreference.com/w/cpp/thread/condition_variable.

This primitive will wake up if the context was shut down.

Definition at line 334 of file clock.hpp.

Member Function Documentation

◆ mutex()

std::mutex & rclcpp::ClockConditionalVariable::mutex ( )

Returns the internal mutex. In order to be race free with the context shutdown, this mutex must be used for the wait_until call.

Definition at line 606 of file clock.cpp.

◆ notify_one()

void rclcpp::ClockConditionalVariable::notify_one ( )

Notify the blocked thread, that is should reevaluate the wakeup condition. E.g. the given pred function in wait_until shall be reevaluated.

Definition at line 592 of file clock.cpp.

◆ wait_until()

bool rclcpp::ClockConditionalVariable::wait_until ( std::unique_lock< std::mutex > &  lock,
rclcpp::Time  until,
const std::function< bool()> &  pred 
)

Calling this function will block the current thread, until abs_time is reached, or pred returns true.

Parameters
lockA locked lock. The lock must be locked at call time, or this method will throw. The lock will be atomically released and this thread will blocked. The given lock must be created using the mutex returned my mutex().
abs_timeThe time until which this thread shall be blocked.
predmay be called in cased of spurious wakeups, but must be called every time notify_one() was called. During the call to pred, the given lock will be locked. This method will return, if pred returns true.
Returns
true if until was reached.

Definition at line 598 of file clock.cpp.


The documentation for this class was generated from the following files: