Function rcl_wait_set_init

Function Documentation

rcl_ret_t rcl_wait_set_init(rcl_wait_set_t *wait_set, size_t number_of_subscriptions, size_t number_of_guard_conditions, size_t number_of_timers, size_t number_of_clients, size_t number_of_services, size_t number_of_events, rcl_context_t *context, rcl_allocator_t allocator)

Initialize a rcl wait set with space for items to be waited on.

This function allocates space for the subscriptions and other wait-able entities that can be stored in the wait set. It also sets the allocator to the given allocator and initializes the pruned member to be false.

The wait_set struct should be allocated and initialized to NULL. If the wait_set is allocated but the memory is uninitialized the behavior is undefined. Calling this function on a wait set that has already been initialized will result in an error. A wait set can be reinitialized if rcl_wait_set_fini() was called on it.

To use the default allocator use rcl_get_default_allocator().

Expected usage:

#include <rcl/wait.h>

rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
rcl_ret_t ret =
  rcl_wait_set_init(&wait_set, 42, 42, 42, 42, 42, &context, rcl_get_default_allocator());
// ... error handling, then use it, then call the matching fini:
ret = rcl_wait_set_fini(&wait_set);
// ... error handling

Attribute

Adherence

Allocates Memory

Yes

Thread-Safe

No

Uses Atomics

No

Lock-Free

Yes

Parameters:
  • wait_set[inout] the wait set struct to be initialized

  • number_of_subscriptions[in] non-zero size of the subscriptions set

  • number_of_guard_conditions[in] non-zero size of the guard conditions set

  • number_of_timers[in] non-zero size of the timers set

  • number_of_clients[in] non-zero size of the clients set

  • number_of_services[in] non-zero size of the services set

  • number_of_events[in] non-zero size of the events set

  • context[in] the context that the wait set should be associated with

  • allocator[in] the allocator to use when allocating space in the sets

Returns:

RCL_RET_OK if the wait set is initialized successfully, or

Returns:

RCL_RET_ALREADY_INIT if the wait set is not zero initialized, or

Returns:

RCL_RET_NOT_INIT if the given context is invalid, or

Returns:

RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or

Returns:

RCL_RET_BAD_ALLOC if allocating memory failed, or

Returns:

RCL_RET_WAIT_SET_INVALID if the wait set is not destroyed properly, or

Returns:

RCL_RET_ERROR if an unspecified error occurs.