Speed up time sync after standby

This commit is contained in:
badaix 2020-04-21 11:01:07 +02:00
parent c85b16454c
commit bfbd9e05a7
3 changed files with 11 additions and 6 deletions

View file

@ -16,7 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
***/ ***/
#ifndef NOMINMAX
#define NOMINMAX #define NOMINMAX
#endif // NOMINMAX
#include "stream.hpp" #include "stream.hpp"
#include "common/aixlog.hpp" #include "common/aixlog.hpp"

View file

@ -19,6 +19,8 @@
#include "time_provider.hpp" #include "time_provider.hpp"
#include "common/aixlog.hpp" #include "common/aixlog.hpp"
#include <chrono>
TimeProvider::TimeProvider() : diffToServer_(0) TimeProvider::TimeProvider() : diffToServer_(0)
{ {
@ -37,18 +39,19 @@ void TimeProvider::setDiff(const tv& c2s, const tv& s2c)
void TimeProvider::setDiffToServer(double ms) void TimeProvider::setDiffToServer(double ms)
{ {
static int32_t lastTimeSync = 0; using namespace std::chrono_literals;
timeval now; auto now = std::chrono::system_clock::now();
chronos::steadytimeofday(&now); static auto lastTimeSync = now;
auto diff = chronos::abs(now - lastTimeSync);
/// clear diffBuffer if last update is older than a minute /// 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"; LOG(INFO) << "Last time sync older than a minute. Clearing time buffer\n";
diffToServer_ = static_cast<chronos::usec::rep>(ms * 1000); diffToServer_ = static_cast<chronos::usec::rep>(ms * 1000);
diffBuffer_.clear(); diffBuffer_.clear();
} }
lastTimeSync = now.tv_sec; lastTimeSync = now;
diffBuffer_.add(static_cast<chronos::usec::rep>(ms * 1000)); diffBuffer_.add(static_cast<chronos::usec::rep>(ms * 1000));
diffToServer_ = diffBuffer_.median(); diffToServer_ = diffBuffer_.median();

View file

@ -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
{ {
} }
}; };