Skip to content

Commit c5e903a

Browse files
sloretzbrawner
andauthored
[Foxy backport] Use valid clock in case of issue in rcl_timer_init (#795) Store reference to rcl_clock_t instead of copy (#797) (#805)
* Use valid clock in case of issue in rcl_timer_init (#795) * Use valid clock in case of issue Signed-off-by: Stephen Brawner <[email protected]> * Cleanup Signed-off-by: Stephen Brawner <[email protected]> Signed-off-by: Shane Loretz <[email protected]> * Store reference to rcl_clock_t instead of copy (#797) rcl_clock_t can't be trivially copied because adding or removing clock jump callbacks to a copy will free the pointer held by the original instance. Signed-off-by: Shane Loretz<[email protected]> Signed-off-by: Shane Loretz <[email protected]> Co-authored-by: brawner <[email protected]>
1 parent 055d7eb commit c5e903a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

rcl_action/src/rcl_action/action_server.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ rcl_action_server_init(
158158
action_server->impl->options = *options; // copy options
159159
action_server->impl->goal_handles = NULL;
160160
action_server->impl->num_goal_handles = 0u;
161-
action_server->impl->clock.type = RCL_CLOCK_UNINITIALIZED;
161+
action_server->impl->clock = NULL;
162162

163163
rcl_ret_t ret = RCL_RET_OK;
164164
// Initialize services
@@ -170,10 +170,13 @@ rcl_action_server_init(
170170
PUBLISHER_INIT(feedback);
171171
PUBLISHER_INIT(status);
172172

173-
// Initialize Timer
173+
// Store reference to clock
174+
action_server->impl->clock = clock;
175+
176+
// Initialize Timer
174177
ret = rcl_timer_init(
175-
&action_server->impl->expire_timer, clock, node->context, options->result_timeout.nanoseconds,
176-
NULL, allocator);
178+
&action_server->impl->expire_timer, action_server->impl->clock, node->context,
179+
options->result_timeout.nanoseconds, NULL, allocator);
177180
if (RCL_RET_OK != ret) {
178181
goto fail;
179182
}
@@ -183,9 +186,6 @@ rcl_action_server_init(
183186
goto fail;
184187
}
185188

186-
// Copy clock
187-
action_server->impl->clock = *clock;
188-
189189
// Copy action name
190190
action_server->impl->action_name = rcutils_strdup(action_name, allocator);
191191
if (NULL == action_server->impl->action_name) {
@@ -235,6 +235,8 @@ rcl_action_server_fini(rcl_action_server_t * action_server, rcl_node_t * node)
235235
if (rcl_timer_fini(&action_server->impl->expire_timer) != RCL_RET_OK) {
236236
ret = RCL_RET_ERROR;
237237
}
238+
// Ditch clock reference
239+
action_server->impl->clock = NULL;
238240
// Deallocate action name
239241
rcl_allocator_t allocator = action_server->impl->options.allocator;
240242
if (action_server->impl->action_name) {
@@ -380,7 +382,7 @@ rcl_action_accept_new_goal(
380382
rcl_action_goal_info_t goal_info_stamp_now = rcl_action_get_zero_initialized_goal_info();
381383
goal_info_stamp_now = *goal_info;
382384
rcl_time_point_value_t now_time_point;
383-
rcl_ret_t ret = rcl_clock_get_now(&action_server->impl->clock, &now_time_point);
385+
rcl_ret_t ret = rcl_clock_get_now(action_server->impl->clock, &now_time_point);
384386
if (RCL_RET_OK != ret) {
385387
return NULL; // Error already set
386388
}
@@ -584,7 +586,7 @@ rcl_action_expire_goals(
584586

585587
// Get current time (nanosec)
586588
int64_t current_time;
587-
rcl_ret_t ret = rcl_clock_get_now(&action_server->impl->clock, &current_time);
589+
rcl_ret_t ret = rcl_clock_get_now(action_server->impl->clock, &current_time);
588590
if (RCL_RET_OK != ret) {
589591
return RCL_RET_ERROR;
590592
}
@@ -659,7 +661,7 @@ rcl_action_expire_goals(
659661
action_server->impl->options.result_timeout.nanoseconds,
660662
action_server->impl->goal_handles,
661663
action_server->impl->num_goal_handles,
662-
&action_server->impl->clock);
664+
action_server->impl->clock);
663665

664666
// If argument is not null, then set it
665667
if (NULL != num_expired) {
@@ -680,7 +682,7 @@ rcl_action_notify_goal_done(
680682
action_server->impl->options.result_timeout.nanoseconds,
681683
action_server->impl->goal_handles,
682684
action_server->impl->num_goal_handles,
683-
&action_server->impl->clock);
685+
action_server->impl->clock);
684686
}
685687

686688
rcl_ret_t

rcl_action/src/rcl_action/action_server_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct rcl_action_server_impl_t
3333
rcl_action_goal_handle_t ** goal_handles;
3434
size_t num_goal_handles;
3535
// Clock
36-
rcl_clock_t clock;
36+
rcl_clock_t * clock;
3737
// Wait set records
3838
size_t wait_set_goal_service_index;
3939
size_t wait_set_cancel_service_index;

0 commit comments

Comments
 (0)