summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/progress.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2018-05-30 11:45:16 +0000
committerJulian Andres Klode <jak@debian.org>2018-05-30 11:45:16 +0000
commitc105a808366867e5476bd4d1ea7fe1c1e9795948 (patch)
treeea1a9d696a4571d6637b8aaa97dcba6be86bdd0a /apt-pkg/contrib/progress.cc
parent819426013c6ca6310bb469440702b6295dba4498 (diff)
parentf6655a1138a11e80884959014939a25f23a1e308 (diff)
Merge branch 'fix/usesteadyclockforprogress' into 'master'
Fix/usesteadyclockforprogress See merge request apt-team/apt!19
Diffstat (limited to 'apt-pkg/contrib/progress.cc')
-rw-r--r--apt-pkg/contrib/progress.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc
index 3bccc48d4..806bd47f8 100644
--- a/apt-pkg/contrib/progress.cc
+++ b/apt-pkg/contrib/progress.cc
@@ -14,6 +14,7 @@
#include <apt-pkg/progress.h>
#include <cmath>
+#include <chrono>
#include <cstring>
#include <iostream>
#include <string>
@@ -115,12 +116,18 @@ bool OpProgress::CheckChange(float Interval)
return false;
// Check time delta
- struct timeval Now;
- gettimeofday(&Now,0);
- decltype(Interval) const Diff = Now.tv_sec - LastTime.tv_sec + (Now.tv_usec - LastTime.tv_usec)/1000000.0;
- if (Diff < Interval)
+ auto const Now = std::chrono::steady_clock::now().time_since_epoch();
+ auto const Now_sec = std::chrono::duration_cast<std::chrono::seconds>(Now);
+ auto const Now_usec = std::chrono::duration_cast<std::chrono::microseconds>(Now - Now_sec);
+ struct timeval NowTime = { Now_sec.count(), Now_usec.count() };
+
+ std::chrono::duration<decltype(Interval)> Delta =
+ std::chrono::seconds(NowTime.tv_sec - LastTime.tv_sec) +
+ std::chrono::microseconds(NowTime.tv_sec - LastTime.tv_usec);
+
+ if (Delta.count() < Interval)
return false;
- LastTime = Now;
+ LastTime = NowTime;
return true;
}
/*}}}*/