From 2ec8d3bf616c20f270f84146619973bad78bf0cc Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Mon, 28 Mar 2022 11:21:52 -0700 Subject: [PATCH] use uint64_t for timer period. Signed-off-by: Tomoya Fujita --- rcl/include/rcl/timer.h | 18 +++++++++--------- rcl/src/rcl/timer.c | 4 ++-- rcl/test/rcl/test_timer.cpp | 8 ++++---- rcl_action/src/rcl_action/action_server.c | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/rcl/include/rcl/timer.h b/rcl/include/rcl/timer.h index 8316645a1..38443388b 100644 --- a/rcl/include/rcl/timer.h +++ b/rcl/include/rcl/timer.h @@ -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. * *
* Attribute | Adherence @@ -371,10 +371,10 @@ 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] - * [1] if `atomic_is_lock_free()` returns true for `atomic_int_least64_t` + * [1] if `atomic_is_lock_free()` returns true for `atomic_uint_least64_t` * * \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. @@ -382,7 +382,7 @@ rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_sin 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. /** @@ -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. * *
* Attribute | Adherence @@ -400,11 +400,11 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period); * Thread-Safe | Yes * Uses Atomics | Yes * Lock-Free | Yes [1] - * [1] if `atomic_is_lock_free()` returns true for `atomic_int_least64_t` + * [1] if `atomic_is_lock_free()` returns true for `atomic_uint_least64_t` * * \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. @@ -412,7 +412,7 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period); 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. /** diff --git a/rcl/src/rcl/timer.c b/rcl/src/rcl/timer.c index 6c760be96..1f712cef4 100644 --- a/rcl/src/rcl/timer.c +++ b/rcl/src/rcl/timer.c @@ -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); @@ -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); diff --git a/rcl/test/rcl/test_timer.cpp b/rcl/test/rcl/test_timer.cpp index 66ed38c1c..391f81666 100644 --- a/rcl/test/rcl/test_timer.cpp +++ b/rcl/test/rcl/test_timer.cpp @@ -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)); @@ -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)); @@ -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(); diff --git a/rcl_action/src/rcl_action/action_server.c b/rcl_action/src/rcl_action/action_server.c index 63580c40f..c25faed6d 100644 --- a/rcl_action/src/rcl_action/action_server.c +++ b/rcl_action/src/rcl_action/action_server.c @@ -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; }