aboutsummaryrefslogtreecommitdiff
path: root/absl/time/clock.cc
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2024-09-03 11:49:29 -0400
committerBenjamin Barenblat <bbaren@google.com>2024-09-03 11:49:29 -0400
commitc1afa8b8238c25591ca80d068477aa7d4ce05fc8 (patch)
tree284a9f8b319de5783ff83ad004a9e390cb60fd0d /absl/time/clock.cc
parent23778b53f420f54eebc195dd8430e79bda165e5b (diff)
parent4447c7562e3bc702ade25105912dce503f0c4010 (diff)
downloadabseil-c1afa8b8238c25591ca80d068477aa7d4ce05fc8.tar.gz
abseil-c1afa8b8238c25591ca80d068477aa7d4ce05fc8.tar.bz2
abseil-c1afa8b8238c25591ca80d068477aa7d4ce05fc8.zip
Merge new upstream LTS 20240722.0
Diffstat (limited to 'absl/time/clock.cc')
-rw-r--r--absl/time/clock.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/absl/time/clock.cc b/absl/time/clock.cc
index aa74367b..ecd539e5 100644
--- a/absl/time/clock.cc
+++ b/absl/time/clock.cc
@@ -88,11 +88,25 @@ ABSL_NAMESPACE_END
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace time_internal {
+
+// On some processors, consecutive reads of the cycle counter may yield the
+// same value (weakly-increasing). In debug mode, clear the least significant
+// bits to discourage depending on a strictly-increasing Now() value.
+// In x86-64's debug mode, discourage depending on a strictly-increasing Now()
+// value.
+#if !defined(NDEBUG) && defined(__x86_64__)
+constexpr int64_t kCycleClockNowMask = ~int64_t{0xff};
+#else
+constexpr int64_t kCycleClockNowMask = ~int64_t{0};
+#endif
+
// This is a friend wrapper around UnscaledCycleClock::Now()
// (needed to access UnscaledCycleClock).
class UnscaledCycleClockWrapperForGetCurrentTime {
public:
- static int64_t Now() { return base_internal::UnscaledCycleClock::Now(); }
+ static int64_t Now() {
+ return base_internal::UnscaledCycleClock::Now() & kCycleClockNowMask;
+ }
};
} // namespace time_internal