Skip to content

Commit

Permalink
Move lifetime management completly to C
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
  • Loading branch information
ivanpauno committed Feb 12, 2020
1 parent 80a71b7 commit cd37c5a
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 162 deletions.
1 change: 0 additions & 1 deletion rclpy/rclpy/guard_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, callback, callback_group, context=None):
self._context = get_default_context() if context is None else context
with self._context.handle as capsule:
self.__handle = Handle(_rclpy.rclpy_create_guard_condition(capsule))
self.__handle.requires(self._context.handle)
self.callback = callback
self.callback_group = callback_group
# True when the callback is ready to fire but has not been "taken" by an executor
Expand Down
17 changes: 0 additions & 17 deletions rclpy/rclpy/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,6 @@ def destroy(self, then=None):
if 0 == self.__use_count:
self.__destroy()

def requires(self, req_handle):
"""
Add a required handle.
Indicates that the object manged by `req_handle` has to live longer than the object
managed by this handle.
"""
assert isinstance(req_handle, Handle)
with self.__lock, req_handle.__lock:
if not self.__valid:
raise InvalidHandle('Cannot require a new handle if already destroyed')
if req_handle.__valid:
_rclpy_handle.rclpy_handle_add_dependency(self.__capsule, req_handle.__capsule)
else:
# required handle destroyed before we could link to it, destroy self
self.destroy()

def _get_capsule(self):
"""
Get the pycapsule managed by this handle.
Expand Down
7 changes: 0 additions & 7 deletions rclpy/rclpy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def __init__(
validate_namespace(namespace)
# Should not get to this point
raise RuntimeError('rclpy_create_node failed for unknown reason')
self.__handle.requires(self._context.handle)
with self.handle as capsule:
self._logger = get_logger(_rclpy.rclpy_get_node_logger_name(capsule))

Expand Down Expand Up @@ -1141,7 +1140,6 @@ def create_publisher(
self._validate_topic_or_service_name(topic)

publisher_handle = Handle(publisher_capsule)
publisher_handle.requires(self.handle)

publisher = Publisher(
publisher_handle, msg_type, topic, qos_profile,
Expand Down Expand Up @@ -1200,7 +1198,6 @@ def create_subscription(
self._validate_topic_or_service_name(topic)

subscription_handle = Handle(subscription_capsule)
subscription_handle.requires(self.handle)

subscription = Subscription(
subscription_handle, msg_type,
Expand Down Expand Up @@ -1248,7 +1245,6 @@ def create_client(
self._validate_topic_or_service_name(srv_name, is_service=True)

client_handle = Handle(client_capsule)
client_handle.requires(self.handle)

client = Client(
self.context,
Expand Down Expand Up @@ -1296,7 +1292,6 @@ def create_service(
self._validate_topic_or_service_name(srv_name, is_service=True)

service_handle = Handle(service_capsule)
service_handle.requires(self.handle)

service = Service(
service_handle,
Expand Down Expand Up @@ -1331,7 +1326,6 @@ def create_timer(
if clock is None:
clock = self._clock
timer = Timer(callback, callback_group, timer_period_nsec, clock, context=self.context)
timer.handle.requires(self.handle)

self.__timers.append(timer)
callback_group.add_entity(timer)
Expand All @@ -1347,7 +1341,6 @@ def create_guard_condition(
if callback_group is None:
callback_group = self.default_callback_group
guard = GuardCondition(callback, callback_group, context=self.context)
guard.handle.requires(self.handle)

self.__guards.append(guard)
callback_group.add_entity(guard)
Expand Down
1 change: 0 additions & 1 deletion rclpy/rclpy/qos_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def __init__(
with parent_handle as parent_capsule:
event_capsule = _rclpy.rclpy_create_event(event_type, parent_capsule)
self._event_handle = Handle(event_capsule)
self._event_handle.requires(self._parent_handle)
self._ready_to_take_data = False
self._event_index = None

Expand Down
2 changes: 0 additions & 2 deletions rclpy/rclpy/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def __init__(self, callback, callback_group, timer_period_ns, clock, *, context=
with self._clock.handle as clock_capsule, self._context.handle as context_capsule:
self.__handle = Handle(_rclpy.rclpy_create_timer(
clock_capsule, context_capsule, timer_period_ns))
self.__handle.requires(self._clock.handle)
self.__handle.requires(self._context.handle)
self.timer_period_ns = timer_period_ns
self.callback = callback
self.callback_group = callback_group
Expand Down
Loading

0 comments on commit cd37c5a

Please sign in to comment.