From 8e45685002488b55f24cb67a795eaa8d1c3297a1 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Fri, 26 May 2023 09:43:35 -0700 Subject: Disable the use of the fast GetCurrentTimeNanos() algorithm based on the cyclecounter by default, since it may be unsafe in some situations (for example, if the system may enter a sleep state). Fixes #1460 PiperOrigin-RevId: 535641718 Change-Id: I41c9cc4bc7a8ae7280ff9df00abd57668205045b --- absl/time/clock.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/absl/time/clock.cc b/absl/time/clock.cc index 2bf53d9c..aa74367b 100644 --- a/absl/time/clock.cc +++ b/absl/time/clock.cc @@ -48,17 +48,16 @@ Time Now() { ABSL_NAMESPACE_END } // namespace absl -// Decide if we should use the fast GetCurrentTimeNanos() algorithm -// based on the cyclecounter, otherwise just get the time directly -// from the OS on every call. This can be chosen at compile-time via +// Decide if we should use the fast GetCurrentTimeNanos() algorithm based on the +// cyclecounter, otherwise just get the time directly from the OS on every call. +// By default, the fast algorithm based on the cyclecount is disabled because in +// certain situations, for example, if the OS enters a "sleep" mode, it may +// produce incorrect values immediately upon waking. +// This can be chosen at compile-time via // -DABSL_USE_CYCLECLOCK_FOR_GET_CURRENT_TIME_NANOS=[0|1] #ifndef ABSL_USE_CYCLECLOCK_FOR_GET_CURRENT_TIME_NANOS -#if ABSL_USE_UNSCALED_CYCLECLOCK -#define ABSL_USE_CYCLECLOCK_FOR_GET_CURRENT_TIME_NANOS 1 -#else #define ABSL_USE_CYCLECLOCK_FOR_GET_CURRENT_TIME_NANOS 0 #endif -#endif #if defined(__APPLE__) || defined(_WIN32) #include "absl/time/internal/get_current_time_chrono.inc" -- cgit v1.2.3