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 uint64_t for timer period. #974

Closed
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
18 changes: 9 additions & 9 deletions rcl/include/rcl/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_sin
/**
* This function retrieves the period and copies it into the given variable.
*
* The period argument must be a pointer to an already allocated int64_t.
* The period argument must be a pointer to an already allocated uint64_t.
*
* <hr>
* Attribute | Adherence
Expand All @@ -371,18 +371,18 @@ rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_sin
* Thread-Safe | Yes
* Uses Atomics | Yes
* Lock-Free | Yes [1]
* <i>[1] if `atomic_is_lock_free()` returns true for `atomic_int_least64_t`</i>
* <i>[1] if `atomic_is_lock_free()` returns true for `atomic_uint_least64_t`</i>
*
* \param[in] timer the handle to the timer which is being queried
* \param[out] period the int64_t in which the period is stored
* \param[out] period the uint64_t in which the period is stored
* \return #RCL_RET_OK if the period was retrieved successfully, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_ERROR an unspecified error occur.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
rcl_timer_get_period(const rcl_timer_t * timer, uint64_t * period);

/// Exchange the period of the timer and return the previous period.
/**
Expand All @@ -391,7 +391,7 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
*
* Exchanging (changing) the period will not affect already waiting wait sets.
*
* The old_period argument must be a pointer to an already allocated int64_t.
* The old_period argument must be a pointer to an already allocated uint64_t.
*
* <hr>
* Attribute | Adherence
Expand All @@ -400,19 +400,19 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
* Thread-Safe | Yes
* Uses Atomics | Yes
* Lock-Free | Yes [1]
* <i>[1] if `atomic_is_lock_free()` returns true for `atomic_int_least64_t`</i>
* <i>[1] if `atomic_is_lock_free()` returns true for `atomic_uint_least64_t`</i>
*
* \param[in] timer the handle to the timer which is being modified
* \param[out] new_period the int64_t to exchange into the timer
* \param[out] old_period the int64_t in which the previous period is stored
* \param[in] new_period the uint64_t to exchange into the timer
* \param[out] old_period the uint64_t in which the previous period is stored
* \return #RCL_RET_OK if the period was retrieved successfully, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_ERROR an unspecified error occur.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
rcl_timer_exchange_period(const rcl_timer_t * timer, uint64_t new_period, uint64_t * old_period);

/// Return the current timer callback.
/**
Expand Down
4 changes: 2 additions & 2 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ rcl_timer_get_time_since_last_call(
}

rcl_ret_t
rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period)
rcl_timer_get_period(const rcl_timer_t * timer, uint64_t * period)
{
RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(period, RCL_RET_INVALID_ARGUMENT);
Expand All @@ -352,7 +352,7 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period)
}

rcl_ret_t
rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period)
rcl_timer_exchange_period(const rcl_timer_t * timer, uint64_t new_period, uint64_t * old_period)
{
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);

Expand Down
8 changes: 4 additions & 4 deletions rcl/test/rcl/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ TEST_F(TestPreInitTimer, test_timer_clock) {
TEST_F(TestPreInitTimer, test_timer_call) {
int64_t next_call_start = 0;
int64_t next_call_end = 0;
int64_t old_period = 0;
uint64_t old_period = 0;
times_called = 0;

EXPECT_EQ(RCL_RET_OK, rcl_timer_get_time_until_next_call(&timer, &next_call_start));
Expand All @@ -804,7 +804,7 @@ TEST_F(TestPreInitTimer, test_timer_call) {

next_call_start = next_call_end;
ASSERT_EQ(RCL_RET_OK, rcl_timer_exchange_period(&timer, 0, &old_period));
EXPECT_EQ(RCL_S_TO_NS(1), old_period);
EXPECT_EQ((uint64_t)RCL_S_TO_NS(1), old_period);
ASSERT_EQ(RCL_RET_OK, rcl_timer_call(&timer)) << rcl_get_error_string().str;
EXPECT_EQ(times_called, 4);
EXPECT_EQ(RCL_RET_OK, rcl_timer_get_time_until_next_call(&timer, &next_call_end));
Expand Down Expand Up @@ -884,9 +884,9 @@ TEST_F(TestPreInitTimer, test_invalid_init_fini) {
}

TEST_F(TestPreInitTimer, test_timer_get_period) {
int64_t period = 0;
uint64_t period = 0;
ASSERT_EQ(RCL_RET_OK, rcl_timer_get_period(&timer, &period));
EXPECT_EQ(RCL_S_TO_NS(1), period);
EXPECT_EQ((uint64_t)RCL_S_TO_NS(1), period);

EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_timer_get_period(nullptr, &period));
rcl_reset_error();
Expand Down
4 changes: 2 additions & 2 deletions rcl_action/src/rcl_action/action_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ _recalculate_expire_timer(
return ret;
}
// Make timer fire when next goal expires
int64_t old_period;
ret = rcl_timer_exchange_period(expire_timer, minimum_period, &old_period);
uint64_t old_period;
ret = rcl_timer_exchange_period(expire_timer, (uint64_t)minimum_period, &old_period);
if (RCL_RET_OK != ret) {
return ret;
}
Expand Down