Repository navigation
Description
Feature request
Feature description
This is a proposal to add rcl_..._shutdown functions in addition to rcl_..._fini for publishers, subscribers, clients, services, and nodes. The motivation comes from rclpy where memory is freed by a garbage collector, but there is still a desire to get rid of topics/services/actions without waiting for a garbage collector to run.
This would make it defined behavior to call an rcl method with something that has been shutdown but not fini'd. This would eliminate the need make sure an entity is not being used before destroying it, and also eliminate the need to destroy Publishers/subscribers/clients/services etc before the node that they were created from.
Implementation considerations
Having a split between shutdown and destroy would make ros2/rclpy#319 unnecessary. node.destroy_publisher() would call rcl_..._shutdown, and the pycapsule destructor would call rcl_..._fini.
After an entity is shutdown any attempt to use it is should be an error. Calling rcl_node_shutdown should make any use of an entity created from the node invalid.
It should be safe to shutdown an entity even if there is a call to rcl_wait that is waiting on that entity. One option is to wake the wait set before calling rmw_destroy_... on the entity. Another would be for shutdown to fail if the entity is currently in a wait set.
An error code to rcl_ret_t should be added for something being invalid due to being shut down.
rcl_..._shutdown would call rmw_destroy_... on the thing being shutdown. For nodes this means calling rmw_destroy_... on every entity created from the node first. rcl_node_t would have to keep pointers to entities created from it.
The rcl type must have some state to say the rmw type has been free'd but the rcl type has not. This could be done by setting the rmw type to NULL after shutting down the type.
Wait sets and guard conditions also have init and fini methods, but they aren't visible outside the process. Since they just use memory there probably isn't any value in having a separate shutdown function.
Activity
sloretz commentedon May 1, 2019
Tagged as
backlogas this idea seems a lot more complicated than I was expecting and needs more thought