Change of Waitable waitset interface
@wjwwood is already working on this.
Since Feb 9, 2024.
- Dominant language
- C++
- Stars
- 805
- Forks
- 564
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 27
Description
Feature request
Feature description
Currently the rclcpp::Waitable operates directly on the waitset.
add_to_wait_set(rcl_wait_set_t * wait_set) = 0;
virtual
bool
is_ready(rcl_wait_set_t * wait_set) = 0;
The problem here is, that the executor is not directly aware of the changes to the waitset done
bye the Waitable. Therefore the executor can not do certain optimizations, like use precomputed waitsets.
Another drawback of the current implementation is, that we need to hold a shared_ptr to the waitable
while we call rcl::wait in order to make sure that the rcl primitives in the waitset do not get deleted.
Therefore I would propose to change the interface of the rclcpp::Waitable to something like this:
struct WaitableSetHandles
{
std::vector<std::shared_ptr<rcl_subscription_t> subscription_handles;
std::vector<std::shared_ptr<rcl_client_t> client_handles;
.
.
.
// If this triggers, the executer must request a new WaitableSetHandles from the waitable
std::optional<std::shared_ptr<rcl_guard_condition_t>> waitable_changed;
};
struct WaitableSetHandleState
{
std::std::vector<bool> subscription_is_ready;
std::std::vector<bool> client_is_ready;
.
.
.
};
class Waitable
{
/**
* Will be called before rcl::wait will be called. This may
* be used for rearming guard_conditions, if there is still
* data to be processed.
*/
virtual void before_wait_cb();
/**
* Returns all rcl handles used by this waitable
*/
virtual WaitableSetHandles getWaitsetHandles() = 0;
/**
* Returns all rcl handles used by this waitable
*/
virtual bool
is_ready(WaitableSetHandleState * state) = 0;
};
Implementation considerations
This has an impact on a public interface, and though might/will break downstream implementations.
On the pro side, we can optimize a code path that is being heavily used reducing the cpu load and latency of the standard
executors.
Note, with this change, we could also integrate an optimization into the executor, that should get rid of most of the std::weak_ptr::lock() calls.
@wjwwood and @mjcarroll whats you opinion and this ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.