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

If timer canceled, rcl_timer_get_time_until_next_call returns TIMER_CANCELED #963

Merged
merged 3 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions rcl/include/rcl/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
* \return #RCL_RET_OK if the timer until next call was successfully calculated, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_TIMER_INVALID if the timer is invalid, or
* \return #RCL_RET_TIMER_CANCELED if the timer is canceled, or
* \return #RCL_RET_ERROR an unspecified error occur.
*/
RCL_PUBLIC
Expand Down
10 changes: 8 additions & 2 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready)
RCL_CHECK_ARGUMENT_FOR_NULL(is_ready, RCL_RET_INVALID_ARGUMENT);
int64_t time_until_next_call;
rcl_ret_t ret = rcl_timer_get_time_until_next_call(timer, &time_until_next_call);
if (ret != RCL_RET_OK) {
if (ret == RCL_RET_TIMER_CANCELED) {
*is_ready = false;
return RCL_RET_OK;
} else if (ret != RCL_RET_OK) {
return ret; // rcl error state should already be set.
}
*is_ready = (time_until_next_call <= 0) && !rcutils_atomic_load_bool(&timer->impl->canceled);
*is_ready = (time_until_next_call <= 0);
return RCL_RET_OK;
}

Expand All @@ -309,6 +312,9 @@ rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_unt
{
RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(time_until_next_call, RCL_RET_INVALID_ARGUMENT);
if (rcutils_atomic_load_bool(&timer->impl->canceled)) {
return RCL_RET_TIMER_CANCELED;
}
rcl_time_point_value_t now;
rcl_ret_t ret = rcl_clock_get_now(timer->impl->clock, &now);
if (ret != RCL_RET_OK) {
Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ TEST_F(TestTimerFixture, test_canceled_timer) {
ret = rcl_timer_cancel(&timer);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;

int64_t time_until_next_call = 0;
ret = rcl_timer_get_time_until_next_call(&timer, &time_until_next_call);
EXPECT_EQ(RCL_RET_TIMER_CANCELED, ret) << rcl_get_error_string().str;

rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
ret = rcl_wait_set_init(&wait_set, 0, 0, 1, 0, 0, 0, context_ptr, rcl_get_default_allocator());
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
Expand Down