Skip to content

Commit

Permalink
consolidate wait set functions (#285)
Browse files Browse the repository at this point in the history
* Consolidate functions to clear wait set

Add rcl_wait_set_clear()
Remove
  rcl_wait_set_clear_subscriptions()
  rcl_wait_set_clear_guard_conditions()
  rcl_wait_set_clear_clients()
  rcl_wait_set_clear_services()
  rcl_wait_set_clear_timers()

* Consolidate functions to resize wait set

Add rcl_wait_set_resize()
Removed
  rcl_wait_set_resize_subscriptions()
  rcl_wait_set_resize_guard_conditions()
  rcl_wait_set_resize_timers()
  rcl_wait_set_resize_clients()
  rcl_wait_set_resize_services()
  • Loading branch information
sloretz authored Aug 27, 2018
1 parent 3aebe9f commit ba9f24b
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 323 deletions.
115 changes: 21 additions & 94 deletions rcl/include/rcl/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ rcl_wait_set_add_subscription(
rcl_wait_set_t * wait_set,
const rcl_subscription_t * subscription);

/// Remove (sets to `NULL`) the subscriptions in the wait set.
/// Remove (sets to `NULL`) all entities in the wait set.
/**
* This function should be used after passing using rcl_wait, but before
* adding new subscriptions to the set.
* adding new entities to the set.
* Sets all of the entries in the underlying rmw array to `NULL`, and sets the
* count in the rmw array to `0`.
*
Expand All @@ -226,7 +226,7 @@ rcl_wait_set_add_subscription(
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[inout] wait_set struct to have its subscriptions cleared
* \param[inout] wait_set struct to have its entities cleared
* \return `RCL_RET_OK` if cleared successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_WAIT_SET_INVALID` if the wait set is zero initialized, or
Expand All @@ -235,20 +235,19 @@ rcl_wait_set_add_subscription(
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_clear_subscriptions(rcl_wait_set_t * wait_set);
rcl_wait_set_clear(rcl_wait_set_t * wait_set);

/// Reallocate space for the subscriptions in the wait set.
/// Reallocate space for entities in the wait set.
/**
* This function will deallocate and reallocate the memory for the
* subscriptions set.
* This function will deallocate and reallocate the memory for all entity sets.
*
* A size of 0 will just deallocate the memory and assign `NULL` to the array.
*
* Allocation and deallocation is done with the allocator given during the
* wait set's initialization.
*
* After calling this function all values in the set will be set to `NULL`,
* effectively the same as calling rcl_wait_set_clear_subscriptions().
* effectively the same as calling rcl_wait_set_clear().
* Similarly, the underlying rmw representation is reallocated and reset:
* all entries are set to `NULL` and the count is set to zero.
*
Expand All @@ -264,8 +263,12 @@ rcl_wait_set_clear_subscriptions(rcl_wait_set_t * wait_set);
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[inout] wait_set struct to have its subscriptions cleared
* \param[in] size a size for the new set
* \param[inout] wait_set struct to be resized
* \param[in] subscriptions_size a size for the new subscriptions set
* \param[in] guard_conditions_size a size for the new subscriptions set
* \param[in] timers_size a size for the new subscriptions set
* \param[in] clients_size a size for the new subscriptions set
* \param[in] services_size a size for the new subscriptions set
* \return `RCL_RET_OK` if resized successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory failed, or
Expand All @@ -274,7 +277,13 @@ rcl_wait_set_clear_subscriptions(rcl_wait_set_t * wait_set);
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_resize_subscriptions(rcl_wait_set_t * wait_set, size_t size);
rcl_wait_set_resize(
rcl_wait_set_t * wait_set,
size_t subscriptions_size,
size_t guard_conditions_size,
size_t timers_size,
size_t clients_size,
size_t services_size);

/// Store a pointer to the guard condition in the next empty spot in the set.
/**
Expand All @@ -288,26 +297,6 @@ rcl_wait_set_add_guard_condition(
rcl_wait_set_t * wait_set,
const rcl_guard_condition_t * guard_condition);

/// Remove (sets to `NULL`) the guard conditions in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_clear_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_clear_guard_conditions(rcl_wait_set_t * wait_set);

/// Reallocate space for the guard conditions in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_resize_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_resize_guard_conditions(rcl_wait_set_t * wait_set, size_t size);

/// Store a pointer to the timer in the next empty spot in the set.
/**
* This function behaves exactly the same as for subscriptions.
Expand All @@ -320,26 +309,6 @@ rcl_wait_set_add_timer(
rcl_wait_set_t * wait_set,
const rcl_timer_t * timer);

/// Remove (sets to `NULL`) the timers in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_clear_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_clear_timers(rcl_wait_set_t * wait_set);

/// Reallocate space for the timers in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_resize_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_resize_timers(rcl_wait_set_t * wait_set, size_t size);

/// Store a pointer to the client in the next empty spot in the set.
/**
* This function behaves exactly the same as for subscriptions.
Expand All @@ -352,26 +321,6 @@ rcl_wait_set_add_client(
rcl_wait_set_t * wait_set,
const rcl_client_t * client);

/// Remove (sets to `NULL`) the clients in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_clear_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_clear_clients(rcl_wait_set_t * wait_set);

/// Reallocate space for the clients in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_resize_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_resize_clients(rcl_wait_set_t * wait_set, size_t size);

/// Store a pointer to the client in the next empty spot in the set.
/**
* This function behaves exactly the same as for subscriptions.
Expand All @@ -384,26 +333,6 @@ rcl_wait_set_add_service(
rcl_wait_set_t * wait_set,
const rcl_service_t * service);

/// Remove (sets to `NULL`) the services in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_clear_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_clear_services(rcl_wait_set_t * wait_set);

/// Reallocate space for the services in the wait set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_resize_subscriptions
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_resize_services(rcl_wait_set_t * wait_set, size_t size);

/// Block until the wait set is ready or until the timeout has been exceeded.
/**
* This function will collect the items in the rcl_wait_set_t and pass them
Expand All @@ -430,9 +359,7 @@ rcl_wait_set_resize_services(rcl_wait_set_t * wait_set, size_t size);
* rcl_ret_t ret = rcl_wait_set_init(&wait_set, 2, 1, 0, 0, 0, rcl_get_default_allocator());
* // ... error handling
* do {
* ret = rcl_wait_set_clear_subscriptions(&wait_set);
* // ... error handling
* ret = rcl_wait_set_clear_guard_conditions(&wait_set);
* ret = rcl_wait_set_clear(&wait_set);
* // ... error handling
* ret = rcl_wait_set_add_subscription(&wait_set, &sub1);
* // ... error handling
Expand Down
Loading

0 comments on commit ba9f24b

Please sign in to comment.