From 01ed7b20aec82163defd3e370e82ee9a83fbb951 Mon Sep 17 00:00:00 2001 From: Konstantin Varlamov Date: Wed, 9 May 2018 12:01:20 -0400 Subject: Firestore C++: in AsyncQueue, use steady_clock instead of system_clock. (#1246) This should prevent weird bugs due to system time readjustments. Because operations are scheduled relative to now, the fact that the resulting timepoint isn't in Unix epoch shouldn't matter. --- Firestore/core/src/firebase/firestore/util/executor_libdispatch.mm | 4 ++-- Firestore/core/src/firebase/firestore/util/executor_std.cc | 2 +- Firestore/core/src/firebase/firestore/util/executor_std.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'Firestore/core/src') diff --git a/Firestore/core/src/firebase/firestore/util/executor_libdispatch.mm b/Firestore/core/src/firebase/firestore/util/executor_libdispatch.mm index b40f0dd..5491fec 100644 --- a/Firestore/core/src/firebase/firestore/util/executor_libdispatch.mm +++ b/Firestore/core/src/firebase/firestore/util/executor_libdispatch.mm @@ -109,7 +109,7 @@ class TimeSlot { void Execute(); void RemoveFromSchedule(); - using TimePoint = std::chrono::time_point; ExecutorLibdispatch* const executor_; @@ -129,7 +129,7 @@ TimeSlot::TimeSlot(ExecutorLibdispatch* const executor, Executor::TaggedOperation&& operation) : executor_{executor}, target_time_{std::chrono::time_point_cast( - std::chrono::system_clock::now()) + + std::chrono::steady_clock::now()) + delay}, tagged_{std::move(operation)} { } diff --git a/Firestore/core/src/firebase/firestore/util/executor_std.cc b/Firestore/core/src/firebase/firestore/util/executor_std.cc index 59197e1..f03a712 100644 --- a/Firestore/core/src/firebase/firestore/util/executor_std.cc +++ b/Firestore/core/src/firebase/firestore/util/executor_std.cc @@ -68,7 +68,7 @@ DelayedOperation ExecutorStd::Schedule(const Milliseconds delay, "Schedule: delay cannot be negative"); namespace chr = std::chrono; - const auto now = chr::time_point_cast(chr::system_clock::now()); + const auto now = chr::time_point_cast(chr::steady_clock::now()); const auto id = PushOnSchedule(std::move(tagged.operation), now + delay, tagged.tag); diff --git a/Firestore/core/src/firebase/firestore/util/executor_std.h b/Firestore/core/src/firebase/firestore/util/executor_std.h index 4ac62e1..58ef96f 100644 --- a/Firestore/core/src/firebase/firestore/util/executor_std.h +++ b/Firestore/core/src/firebase/firestore/util/executor_std.h @@ -55,7 +55,7 @@ class Schedule { // - each operation modifying the queue notifies the condition variable `cv_`. public: using Duration = std::chrono::milliseconds; - using Clock = std::chrono::system_clock; + using Clock = std::chrono::steady_clock; // Entries are scheduled using absolute time. using TimePoint = std::chrono::time_point; -- cgit v1.2.3