From 86dd3ca2b760e80dfc932838dc33db37dc1c45aa Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 15 Mar 2026 20:42:52 -0700 Subject: [PATCH] [hal] Simplify monotonic_clock (#8678) The epoch() function, zero() function, and min_time member are all not part of the std::chrono clock interface. The default constructor of time_point is [documented](https://en.cppreference.com/w/cpp/chrono/time_point/time_point.html) to initialize to the clock's epoch. --- .../native/include/wpi/hal/monotonic_clock.hpp | 16 +++++----------- .../main/native/include/wpi/system/Tracer.hpp | 3 +-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/hal/src/main/native/include/wpi/hal/monotonic_clock.hpp b/hal/src/main/native/include/wpi/hal/monotonic_clock.hpp index 48e10a3848..fce7dfc84d 100644 --- a/hal/src/main/native/include/wpi/hal/monotonic_clock.hpp +++ b/hal/src/main/native/include/wpi/hal/monotonic_clock.hpp @@ -5,7 +5,6 @@ #pragma once #include -#include #include "wpi/hal/HAL.h" @@ -22,17 +21,12 @@ class monotonic_clock { using duration = std::chrono::microseconds; using time_point = std::chrono::time_point; - static time_point now() noexcept { - uint64_t currentTime = HAL_GetMonotonicTime(); - return time_point(std::chrono::microseconds(currentTime)); - } static constexpr bool is_steady = true; - static time_point epoch() noexcept { return time_point(zero()); } - - static duration zero() noexcept { return duration(0); } - - static constexpr time_point min_time = - time_point(duration(std::numeric_limits::min())); + static time_point now() noexcept { + uint64_t currentTime = HAL_GetMonotonicTime(); + return time_point{std::chrono::microseconds{currentTime}}; + } }; + } // namespace wpi::hal diff --git a/wpilibc/src/main/native/include/wpi/system/Tracer.hpp b/wpilibc/src/main/native/include/wpi/system/Tracer.hpp index e7fa4524b3..263cea1dac 100644 --- a/wpilibc/src/main/native/include/wpi/system/Tracer.hpp +++ b/wpilibc/src/main/native/include/wpi/system/Tracer.hpp @@ -66,8 +66,7 @@ class Tracer { static constexpr std::chrono::milliseconds kMinPrintPeriod{1000}; wpi::hal::monotonic_clock::time_point m_startTime; - wpi::hal::monotonic_clock::time_point m_lastEpochsPrintTime = - wpi::hal::monotonic_clock::epoch(); + wpi::hal::monotonic_clock::time_point m_lastEpochsPrintTime; wpi::util::StringMap m_epochs; };