summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-07-14 00:52:43 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-07-14 00:52:43 +0900
commit777b81869086c8c01b18fd06f252c16274aebd91 (patch)
tree663d56b75a199a8564d9e0f7120c65027dfb5d4b
parent01f870221b2044ed14be828e02b00d4f6452d70d (diff)
Add offset value to Timer::clock::now() to treat 0 as special value
-rw-r--r--src/TimerA2.cc14
-rw-r--r--src/TimerA2.h8
2 files changed, 17 insertions, 5 deletions
diff --git a/src/TimerA2.cc b/src/TimerA2.cc
index 850c5355..22023253 100644
--- a/src/TimerA2.cc
+++ b/src/TimerA2.cc
@@ -37,15 +37,23 @@
namespace aria2 {
-Timer::Timer() : tp_(Clock::now()) { reset(); }
+// Add this offset to Timer::Clock::now() so that we can treat 0 value
+// as special case, and normal timeout always applies.
+constexpr auto OFFSET = 24_h;
+
+namespace {
+Timer::Clock::time_point getNow() { return Timer::Clock::now() + OFFSET; }
+} // namespace
+
+Timer::Timer() : tp_(getNow()) { reset(); }
Timer::Timer(const Clock::time_point& tp) : tp_(tp) {}
-void Timer::reset() { tp_ = Clock::now(); }
+void Timer::reset() { tp_ = getNow(); }
Timer::Clock::duration Timer::difference() const
{
- auto now = Clock::now();
+ auto now = getNow();
if (now < tp_) {
return Timer::Clock::duration(0_s);
}
diff --git a/src/TimerA2.h b/src/TimerA2.h
index 2370dba3..baf5ef22 100644
--- a/src/TimerA2.h
+++ b/src/TimerA2.h
@@ -54,9 +54,13 @@ public:
Timer(const Timer& time) = default;
Timer(Timer&& time) = default;
- template <typename duration> constexpr Timer(const duration& t) : tp_(t) {}
+ template <typename duration>
+ constexpr explicit Timer(const duration& t)
+ : tp_(t)
+ {
+ }
- Timer(const Clock::time_point& tp);
+ explicit Timer(const Clock::time_point& tp);
Timer& operator=(Timer&& timer) = default;
Timer& operator=(const Timer& timer) = default;