2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/log.h"
21 struct is_chrono_duration
: std::false_type
25 template<typename Rep
, typename Period
>
26 struct is_chrono_duration
<std::chrono::duration
<Rep
, Period
>> : std::true_type
30 template<typename T
= std::chrono::milliseconds
, bool = is_chrono_duration
<T
>::value
>
34 class EndTime
<T
, true>
37 explicit EndTime(const T duration
) { Set(duration
); }
40 EndTime(const EndTime
& right
) = delete;
43 static constexpr T
Max() { return m_max
; }
45 void Set(const T duration
)
47 m_startTime
= std::chrono::steady_clock::now();
51 m_totalWaitTime
= m_max
;
52 CLog::Log(LOGWARNING
, "duration ({}) greater than max ({}) - duration will be truncated!",
53 duration
.count(), m_max
.count());
57 m_totalWaitTime
= duration
;
61 bool IsTimePast() const
63 const auto now
= std::chrono::steady_clock::now();
65 return ((now
- m_startTime
) >= m_totalWaitTime
);
70 const auto now
= std::chrono::steady_clock::now();
72 const auto left
= ((m_startTime
+ m_totalWaitTime
) - now
);
77 return std::chrono::duration_cast
<T
>(left
);
80 void SetExpired() { m_totalWaitTime
= T::zero(); }
82 void SetInfinite() { m_totalWaitTime
= m_max
; }
84 T
GetInitialTimeoutValue() const { return m_totalWaitTime
; }
86 std::chrono::steady_clock::time_point
GetStartTime() const { return m_startTime
; }
89 std::chrono::steady_clock::time_point m_startTime
;
90 T m_totalWaitTime
= T::zero();
92 static constexpr T m_max
=
93 std::chrono::duration_cast
<T
>(std::chrono::steady_clock::duration::max());
96 } // namespace XbmcThreads