Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use int64_t for period. #1010

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ struct rcl_timer_impl_s
rcl_guard_condition_t guard_condition;
// The user supplied callback.
atomic_uintptr_t callback;
// This is a duration in nanoseconds.
atomic_uint_least64_t period;
// This is a duration in nanoseconds, which is initialized as int64_t
// to be used for internal time calculation.
atomic_int_least64_t period;
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
// This is a time in nanoseconds since an unspecified time.
atomic_int_least64_t last_call_time;
// This is a time in nanoseconds since an unspecified time.
Expand Down Expand Up @@ -92,7 +93,7 @@ void _rcl_timer_time_jump(
}
const int64_t last_call_time = rcutils_atomic_load_int64_t(&timer->impl->last_call_time);
const int64_t next_call_time = rcutils_atomic_load_int64_t(&timer->impl->next_call_time);
const int64_t period = rcutils_atomic_load_uint64_t(&timer->impl->period);
const int64_t period = rcutils_atomic_load_int64_t(&timer->impl->period);
if (RCL_ROS_TIME_ACTIVATED == time_jump->clock_change ||
RCL_ROS_TIME_DEACTIVATED == time_jump->clock_change)
{
Expand Down Expand Up @@ -264,7 +265,7 @@ rcl_timer_call(rcl_timer_t * timer)
(rcl_timer_callback_t)rcutils_atomic_load_uintptr_t(&timer->impl->callback);

int64_t next_call_time = rcutils_atomic_load_int64_t(&timer->impl->next_call_time);
int64_t period = rcutils_atomic_load_uint64_t(&timer->impl->period);
int64_t period = rcutils_atomic_load_int64_t(&timer->impl->period);
// always move the next call time by exactly period forward
// don't use now as the base to avoid extending each cycle by the time
// between the timer being ready and the callback being triggered
Expand Down Expand Up @@ -352,7 +353,7 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period)
RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(timer->impl, RCL_RET_TIMER_INVALID);
RCL_CHECK_ARGUMENT_FOR_NULL(period, RCL_RET_INVALID_ARGUMENT);
*period = rcutils_atomic_load_uint64_t(&timer->impl->period);
*period = rcutils_atomic_load_int64_t(&timer->impl->period);
return RCL_RET_OK;
}

Expand All @@ -364,7 +365,7 @@ rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t
RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(timer->impl, RCL_RET_TIMER_INVALID);
RCL_CHECK_ARGUMENT_FOR_NULL(old_period, RCL_RET_INVALID_ARGUMENT);
*old_period = rcutils_atomic_exchange_uint64_t(&timer->impl->period, new_period);
*old_period = rcutils_atomic_exchange_int64_t(&timer->impl->period, new_period);
RCUTILS_LOG_DEBUG_NAMED(
ROS_PACKAGE_NAME, "Updated timer period from '%" PRIu64 "ns' to '%" PRIu64 "ns'",
*old_period, new_period);
Expand Down Expand Up @@ -424,7 +425,7 @@ rcl_timer_reset(rcl_timer_t * timer)
if (now_ret != RCL_RET_OK) {
return now_ret; // rcl error state should already be set.
}
int64_t period = rcutils_atomic_load_uint64_t(&timer->impl->period);
int64_t period = rcutils_atomic_load_int64_t(&timer->impl->period);
rcutils_atomic_store(&timer->impl->next_call_time, now + period);
rcutils_atomic_store(&timer->impl->canceled, false);
rcl_ret_t ret = rcl_trigger_guard_condition(&timer->impl->guard_condition);
Expand Down