Skip to content

Commit

Permalink
Address memory issue of type hash
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
pablogs9 committed Jul 23, 2023
1 parent 7ec4839 commit bbfdbe4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ struct rcl_client_impl_s
atomic_int_least64_t sequence_number;
rcl_service_event_publisher_t * service_event_publisher;
char * remapped_service_name;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

rcl_client_t
Expand Down Expand Up @@ -190,8 +192,8 @@ rcl_client_init(
ret = RCL_RET_ERROR;
goto destroy_client;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
client->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Client initialized");
TRACETOOLS_TRACEPOINT(
Expand Down
8 changes: 6 additions & 2 deletions rcl/src/rcl/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ rcl_node_init(
node->impl->logger_name = NULL;
node->impl->fq_name = NULL;
node->impl->options = rcl_node_get_default_options();
#ifdef RCL_MICROROS_COMPLETE_IMPL
node->impl->registered_types_by_type_hash = rcutils_get_zero_initialized_hash_map();
node->impl->get_type_description_service = rcl_get_zero_initialized_service();
#endif // RCL_MICROROS_COMPLETE_IMPL
node->context = context;
// Initialize node impl.
ret = rcl_node_options_copy(options, &(node->impl->options));
Expand Down Expand Up @@ -680,7 +682,8 @@ rcl_ret_t rcl_node_type_description_service_init(rcl_node_t * node)
allocator.deallocate(service_name, allocator.state);
return ret;
#else
return RCL_RET_OK;
(void)node;
return RCL_RET_UNSUPPORTED;
#endif //RCL_MICROROS
}

Expand All @@ -702,7 +705,8 @@ rcl_ret_t rcl_node_type_description_service_fini(rcl_node_t * node)

return ret;
#else
return RCL_RET_OK;
(void)node;
return RCL_RET_UNSUPPORTED;
#endif //RCL_MICROROS
}

Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/node_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ struct rcl_node_impl_s
rcl_guard_condition_t * graph_guard_condition;
const char * logger_name;
const char * fq_name;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rcutils_hash_map_t registered_types_by_type_hash;
rcl_service_t get_type_description_service;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

#endif // RCL__NODE_IMPL_H_
2 changes: 1 addition & 1 deletion rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ rcl_publisher_init(
RCL_SET_ERROR_MSG("Failed to register type for subscription");
goto fail;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
publisher->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Publisher initialized");
// context
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/publisher_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ struct rcl_publisher_impl_s
rmw_qos_profile_t actual_qos;
rcl_context_t * context;
rmw_publisher_t * rmw_handle;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

#endif // RCL__PUBLISHER_IMPL_H_
4 changes: 3 additions & 1 deletion rcl/src/rcl/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ struct rcl_service_impl_s
rmw_service_t * rmw_handle;
rcl_service_event_publisher_t * service_event_publisher;
char * remapped_service_name;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

rcl_service_t
Expand Down Expand Up @@ -201,8 +203,8 @@ rcl_service_init(
ret = RCL_RET_ERROR;
goto destroy_service;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
service->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Service initialized");
TRACETOOLS_TRACEPOINT(
Expand Down
2 changes: 1 addition & 1 deletion rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ rcl_subscription_init(
RCL_SET_ERROR_MSG("Failed to register type for subscription");
goto fail;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
subscription->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription initialized");
ret = RCL_RET_OK;
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/subscription_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ struct rcl_subscription_impl_s
rcl_subscription_options_t options;
rmw_qos_profile_t actual_qos;
rmw_subscription_t * rmw_handle;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

#endif // RCL__SUBSCRIPTION_IMPL_H_
4 changes: 3 additions & 1 deletion rcl_action/src/rcl_action/action_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ _rcl_action_get_zero_initialized_client_impl(void)
0,
0,
0,
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_get_zero_initialized_type_hash()
#endif // RCL_MICROROS_COMPLETE_IMPL
};
return null_action_client;
}
Expand Down Expand Up @@ -244,8 +246,8 @@ rcl_action_client_init(
RCL_SET_ERROR_MSG("Failed to register type for action");
goto fail;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
action_client->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Action client initialized");
return ret;
Expand Down
2 changes: 2 additions & 0 deletions rcl_action/src/rcl_action/action_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ typedef struct rcl_action_client_impl_s
size_t wait_set_result_client_index;
size_t wait_set_feedback_subscription_index;
size_t wait_set_status_subscription_index;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
} rcl_action_client_impl_t;


Expand Down
4 changes: 3 additions & 1 deletion rcl_action/src/rcl_action/action_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ rcl_action_server_init(
action_server->impl->goal_handles = NULL;
action_server->impl->num_goal_handles = 0u;
action_server->impl->clock = NULL;
#ifdef RCL_MICROROS_COMPLETE_IMPL
action_server->impl->type_hash = rosidl_get_zero_initialized_type_hash();
#endif // RCL_MICROROS_COMPLETE_IMPL

rcl_ret_t ret = RCL_RET_OK;
// Initialize services
Expand Down Expand Up @@ -208,8 +210,8 @@ rcl_action_server_init(
RCL_SET_ERROR_MSG("Failed to register type for action");
goto fail;
}
#endif // RCL_MICROROS_COMPLETE_IMPL
action_server->impl->type_hash = *type_support->get_type_hash_func(type_support);
#endif // RCL_MICROROS_COMPLETE_IMPL

return ret;
fail:
Expand Down
2 changes: 2 additions & 0 deletions rcl_action/src/rcl_action/action_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ typedef struct rcl_action_server_impl_s
size_t wait_set_cancel_service_index;
size_t wait_set_result_service_index;
size_t wait_set_expire_timer_index;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
} rcl_action_server_impl_t;


Expand Down

0 comments on commit bbfdbe4

Please sign in to comment.