Skip to content

Commit

Permalink
Finalize context iff shutdown. (#196)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored and ahcorde committed Oct 15, 2020
1 parent 5559dfa commit cab4b81
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ struct rmw_context_impl_t
size_t node_count{0};
std::mutex initialization_mutex;

/* Shutdown flag */
bool is_shutdown{false};

/* suffix for GUIDs to construct unique client/service ids
(protected by initialization_mutex) */
uint32_t client_service_id;
Expand Down Expand Up @@ -1148,8 +1151,8 @@ extern "C" rmw_ret_t rmw_shutdown(rmw_context_t * context)
context->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
// Nothing to do here for now.
// This is just the middleware's notification that shutdown was called.
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context->impl, RMW_RET_INVALID_ARGUMENT);
context->impl->is_shutdown = true;
return RMW_RET_OK;
}

Expand All @@ -1161,6 +1164,11 @@ extern "C" rmw_ret_t rmw_context_fini(rmw_context_t * context)
context->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context->impl, RMW_RET_INVALID_ARGUMENT);
if (!context->impl->is_shutdown) {
RCUTILS_SET_ERROR_MSG("context has not been shutdown");
return RMW_RET_INVALID_ARGUMENT;
}
delete context->impl;
*context = rmw_get_zero_initialized_context();
return RMW_RET_OK;
Expand Down

0 comments on commit cab4b81

Please sign in to comment.