aboutsummaryrefslogtreecommitdiff
path: root/src/util/time.h
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-06-24 17:27:15 +0200
committerMacroFake <falke.marco@gmail.com>2022-06-24 17:27:25 +0200
commit1da1c0dd66265b6a610bf6c21bf2090910cb4fb3 (patch)
tree3de1cbe6173d982ed1eda2ea5edafb724592da7a /src/util/time.h
parentf697c068ebd0dfea552c1ff192dfd9d520f1ca9a (diff)
parentfabae3541ac574a1101be8dc54f1499dbbf2f231 (diff)
Merge bitcoin/bitcoin#25456: rpc: Use steady_clock for getrpcinfo durations
fabae3541ac574a1101be8dc54f1499dbbf2f231 rpc: Use steady_clock for getrpcinfo durations (MacroFake) Pull request description: Currently it uses `GetTimeMicros`, which is the system time. Using steady time instead, makes the code type safe and avoids spurious offsets when the system time adjusts. ACKs for top commit: laanwj: Code review ACK fabae3541ac574a1101be8dc54f1499dbbf2f231 w0xlt: Code Review ACK https://github.com/bitcoin/bitcoin/pull/25456/commits/fabae3541ac574a1101be8dc54f1499dbbf2f231 shaavan: Code Review ACK fabae3541ac574a1101be8dc54f1499dbbf2f231 Tree-SHA512: eb25fe3e69bf42ec8a2d4aaa69b435de7654b0d07218ce3e0c03ebaef6eb7f713128779057d012621773a34675a81f5757e7b2502c13b82adaf6e2df970d8c66
Diffstat (limited to 'src/util/time.h')
-rw-r--r--src/util/time.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/util/time.h b/src/util/time.h
index ad91a72860..1a381aab9d 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -40,10 +40,15 @@ void UninterruptibleSleep(const std::chrono::microseconds& n);
* This helper is used to convert durations/time_points before passing them over an
* interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI)
*/
+template <typename Dur1, typename Dur2>
+constexpr auto Ticks(Dur2 d)
+{
+ return std::chrono::duration_cast<Dur1>(d).count();
+}
template <typename Duration, typename Timepoint>
constexpr auto TicksSinceEpoch(Timepoint t)
{
- return std::chrono::time_point_cast<Duration>(t).time_since_epoch().count();
+ return Ticks<Duration>(t.time_since_epoch());
}
constexpr int64_t count_seconds(std::chrono::seconds t) { return t.count(); }
constexpr int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); }