From 59f251ba14edbe984453004efe0788dca62d8dd3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 25 Feb 2011 22:58:51 +0900 Subject: [PATCH] Fixed rounding error in DownloadEngine::run(). This fixes the bug that executeCommand() with Command::STATUS_ALL is not called in every interval correctly because of rounding error in timer. --- src/DownloadEngine.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 95b510f0e..298089e98 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -141,6 +141,13 @@ void executeCommand(std::deque& commands, } } // namespace +namespace { + +// Rounding error in millis +const int A2_DELTA = 10; + +} // namespace + void DownloadEngine::run() { Timer cp; @@ -148,7 +155,7 @@ void DownloadEngine::run() while(!commands_.empty() || !routineCommands_.empty()) { global::wallclock.reset(); calculateStatistics(); - if(cp.differenceInMillis(global::wallclock) >= refreshInterval_) { + if(cp.differenceInMillis(global::wallclock) >= refreshInterval_-A2_DELTA) { refreshInterval_ = DEFAULT_REFRESH_INTERVAL; cp = global::wallclock; executeCommand(commands_, Command::STATUS_ALL);