From 9afe2a5d55800ea9c4ccc01c40bbaefecfb0e849 Mon Sep 17 00:00:00 2001 From: Jackie Kay Date: Wed, 2 Dec 2015 09:47:59 -0800 Subject: [PATCH] Add rmw_create_waitset and rmw_fini_waitset --- rmw/include/rmw/allocators.h | 8 ++++++++ rmw/include/rmw/rmw.h | 24 ++++++++++++++++++++++++ rmw/include/rmw/types.h | 7 +++++++ rmw/src/allocators.c | 14 ++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/rmw/include/rmw/allocators.h b/rmw/include/rmw/allocators.h index bdac299db..df7a06c8b 100644 --- a/rmw/include/rmw/allocators.h +++ b/rmw/include/rmw/allocators.h @@ -79,6 +79,14 @@ RMW_PUBLIC void rmw_service_free(rmw_service_t * service); +RMW_PUBLIC +rmw_waitset_t * +rmw_waitset_allocate(); + +RMW_PUBLIC +void +rmw_waitset_free(rmw_waitset_t * waitset); + #if __cplusplus } #endif diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 50e4e0973..41c5b4a9e 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -182,6 +182,29 @@ RMW_WARN_UNUSED rmw_ret_t rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition); +/// Create a waitset to store conditions that the middleware will block on. +/** + * If max_conditions is 0, the waitset can store an unbounded number of conditions to wait on. + * If max_conditions is greater than 0, the number of conditions that can be attached to the + * waitset is bounded at max_conditions. + * \param[in] fixed_guard_conditions Guard conditions that are attached to the waitset immediately + * after initialization and are not removed from the waitset until rmw_destroy_waitset is called. + * For example, the guard condition for the CTRL-C signal handler is a "fixed condition". + * Must stay valid until rmw_destroy_waitset is called. The caller must keep ownership of the + * allocated guard conditions and deallocate them after rmw_destroy_waitset is called. + * \param[in] max_conditions The maximum number of conditions that can be attached to the waitset. + * \return A pointer to the created waitset, nullptr if an error occurred. + */ +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_waitset_t * +rmw_create_waitset(rmw_guard_conditions_t * fixed_guard_conditions, size_t max_conditions); + +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_destroy_waitset(rmw_waitset_t * waitset); + RMW_PUBLIC RMW_WARN_UNUSED rmw_ret_t @@ -190,6 +213,7 @@ rmw_wait( rmw_guard_conditions_t * guard_conditions, rmw_services_t * services, rmw_clients_t * clients, + rmw_waitset_t * waitset, const rmw_time_t * wait_timeout); RMW_PUBLIC diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 7cbb6609a..70de633e8 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -99,6 +99,13 @@ typedef struct RMW_PUBLIC_TYPE rmw_guard_conditions_t void ** guard_conditions; } rmw_guard_conditions_t; +typedef struct RMW_PUBLIC_TYPE rmw_waitset_t +{ + const char * implementation_identifier; + rmw_guard_conditions_t * fixed_guard_conditions; + void * data; +} rmw_waitset_t; + typedef struct RMW_PUBLIC_TYPE rmw_request_id_t { int8_t writer_guid[16]; diff --git a/rmw/src/allocators.c b/rmw/src/allocators.c index f1ed97f2b..49667e33e 100644 --- a/rmw/src/allocators.c +++ b/rmw/src/allocators.c @@ -121,3 +121,17 @@ rmw_service_free(rmw_service_t * service) // Should have matching overide with rmw_service_allocate rmw_free(service); } + +rmw_waitset_t * +rmw_waitset_allocate() +{ + // Could be overridden with custom (maybe static) client struct allocator + return (rmw_waitset_t *)rmw_allocate(sizeof(rmw_waitset_t)); +} + +void +rmw_waitset_free(rmw_waitset_t * waitset) +{ + // Should have matching overide with rmw_waitset_allocate + rmw_free(waitset); +}