diff --git a/include/realtime_tools/async_function_handler.hpp b/include/realtime_tools/async_function_handler.hpp index 1c35257e..6c8db652 100644 --- a/include/realtime_tools/async_function_handler.hpp +++ b/include/realtime_tools/async_function_handler.hpp @@ -169,7 +169,7 @@ class AsyncFunctionHandler std::unique_lock lock(async_mtx_); stop_async_callback_ = false; trigger_in_progress_ = false; - last_execution_time_ = 0.0; + last_execution_time_ = std::chrono::nanoseconds(0); async_callback_return_ = T(); async_exception_ptr_ = nullptr; } @@ -247,9 +247,12 @@ class AsyncFunctionHandler /// Get the last execution time of the async callback method /** - * @return The last execution time of the async callback method in seconds + * @return The last execution time of the async callback method in nanoseconds */ - double get_last_execution_time() const { return last_execution_time_; } + std::chrono::nanoseconds get_last_execution_time() const + { + return last_execution_time_.load(std::memory_order_relaxed); + } /// Initializes and starts the callback thread /** @@ -289,7 +292,8 @@ class AsyncFunctionHandler async_exception_ptr_ = std::current_exception(); } const auto end_time = std::chrono::steady_clock::now(); - last_execution_time_ = std::chrono::duration(end_time - start_time).count(); + last_execution_time_ = + std::chrono::duration_cast(end_time - start_time); } trigger_in_progress_ = false; } @@ -315,7 +319,7 @@ class AsyncFunctionHandler std::condition_variable async_callback_condition_; std::condition_variable cycle_end_condition_; std::mutex async_mtx_; - std::atomic last_execution_time_; + std::atomic last_execution_time_; std::exception_ptr async_exception_ptr_; }; } // namespace realtime_tools