Skip to content

Commit

Permalink
use rcl_clock_get_now
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Jul 24, 2018
1 parent 252bdaf commit e8f2e34
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ rcl_timer_init(
RCL_SET_ERROR_MSG("timer already initailized, or memory was uninitialized", allocator);
return RCL_RET_ALREADY_INIT;
}
rcl_time_point_value_t now;
rcl_ret_t now_ret = clock->get_now(clock->data, &now);
rcl_time_point_t now;
rcl_ret_t now_ret = rcl_clock_get_now(clock, &now);
if (now_ret != RCL_RET_OK) {
return now_ret; // rcl error state should already be set.
}
rcl_timer_impl_t impl;
impl.clock = clock;
atomic_init(&impl.callback, (uintptr_t)callback);
atomic_init(&impl.period, period);
atomic_init(&impl.last_call_time, now);
atomic_init(&impl.last_call_time, now.nanoseconds);
atomic_init(&impl.canceled, false);
impl.allocator = allocator;
timer->impl = (rcl_timer_impl_t *)allocator.allocate(sizeof(rcl_timer_impl_t), allocator.state);
Expand Down Expand Up @@ -110,18 +110,18 @@ rcl_timer_call(rcl_timer_t * timer)
RCL_SET_ERROR_MSG("timer is canceled", *allocator);
return RCL_RET_TIMER_CANCELED;
}
rcl_time_point_value_t now;
rcl_ret_t now_ret = timer->impl->clock->get_now(timer->impl->clock->data, &now);
rcl_time_point_t now;
rcl_ret_t now_ret = rcl_clock_get_now(timer->impl->clock, &now);
if (now_ret != RCL_RET_OK) {
return now_ret; // rcl error state should already be set.
}
rcl_time_point_value_t previous_ns =
rcl_atomic_exchange_uint64_t(&timer->impl->last_call_time, now);
rcl_atomic_exchange_uint64_t(&timer->impl->last_call_time, now.nanoseconds);
rcl_timer_callback_t typed_callback =
(rcl_timer_callback_t)rcl_atomic_load_uintptr_t(&timer->impl->callback);

if (typed_callback != NULL) {
int64_t since_last_call = now - previous_ns;
int64_t since_last_call = now.nanoseconds - previous_ns;
typed_callback(timer, since_last_call);
}
return RCL_RET_OK;
Expand Down

0 comments on commit e8f2e34

Please sign in to comment.