summaryrefslogtreecommitdiff
path: root/absl/time
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-05-26 09:43:35 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-05-26 09:44:21 -0700
commit8e45685002488b55f24cb67a795eaa8d1c3297a1 (patch)
tree84e57b593ab6a683ba7a6e5d4975e241089cfb18 /absl/time
parent0f718c568b448005bcb6718e7c0f5b6420ace413 (diff)
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
Diffstat (limited to 'absl/time')
-rw-r--r--absl/time/clock.cc13
1 files 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"