From bfbd9e05a72b5535bfe8ea6dbda909d2eb33f52e Mon Sep 17 00:00:00 2001 From: badaix Date: Tue, 21 Apr 2020 11:01:07 +0200 Subject: [PATCH] Speed up time sync after standby --- client/stream.cpp | 2 ++ client/time_provider.cpp | 13 ++++++++----- common/aixlog.hpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/stream.cpp b/client/stream.cpp index f307514e..e99a277f 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -16,7 +16,9 @@ along with this program. If not, see . ***/ +#ifndef NOMINMAX #define NOMINMAX +#endif // NOMINMAX #include "stream.hpp" #include "common/aixlog.hpp" diff --git a/client/time_provider.cpp b/client/time_provider.cpp index 527baf7e..0ed45943 100644 --- a/client/time_provider.cpp +++ b/client/time_provider.cpp @@ -19,6 +19,8 @@ #include "time_provider.hpp" #include "common/aixlog.hpp" +#include + TimeProvider::TimeProvider() : diffToServer_(0) { @@ -37,18 +39,19 @@ void TimeProvider::setDiff(const tv& c2s, const tv& s2c) void TimeProvider::setDiffToServer(double ms) { - static int32_t lastTimeSync = 0; - timeval now; - chronos::steadytimeofday(&now); + using namespace std::chrono_literals; + auto now = std::chrono::system_clock::now(); + static auto lastTimeSync = now; + auto diff = chronos::abs(now - lastTimeSync); /// clear diffBuffer if last update is older than a minute - if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60)) + if (!diffBuffer_.empty() && (diff > 60s)) { LOG(INFO) << "Last time sync older than a minute. Clearing time buffer\n"; diffToServer_ = static_cast(ms * 1000); diffBuffer_.clear(); } - lastTimeSync = now.tv_sec; + lastTimeSync = now; diffBuffer_.add(static_cast(ms * 1000)); diffToServer_ = diffBuffer_.median(); diff --git a/common/aixlog.hpp b/common/aixlog.hpp index 5e7d260a..491f33c9 100644 --- a/common/aixlog.hpp +++ b/common/aixlog.hpp @@ -688,7 +688,7 @@ struct SinkNull : public Sink { } - void log(const Metadata& metadata, const std::string& message) override + void log(const Metadata& /*metadata*/, const std::string& /*message*/) override { } };