-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathdeadline.cpp
48 lines (34 loc) · 1.42 KB
/
deadline.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <userver/engine/deadline.hpp>
#include <userver/logging/log.hpp>
#include <userver/utils/assert.hpp>
#include <userver/utils/datetime/steady_coarse_clock.hpp>
USERVER_NAMESPACE_BEGIN
namespace engine {
using CoarseClock = utils::datetime::SteadyCoarseClock;
bool Deadline::IsReached() const noexcept {
if (!IsReachable()) return false;
if (value_ == kPassed) return true;
return value_ <= TimePoint::clock::now();
}
bool Deadline::IsSurelyReachedApprox() const noexcept {
if (!IsReachable()) return false;
if (value_ == kPassed) return true;
return value_.time_since_epoch() <= CoarseClock::now().time_since_epoch() - CoarseClock::resolution();
}
Deadline::Duration Deadline::TimeLeft() const noexcept {
UASSERT(IsReachable());
if (value_ == kPassed) return Duration::zero();
return value_ - TimePoint::clock::now();
}
Deadline::Duration Deadline::TimeLeftApprox() const noexcept {
UASSERT(IsReachable());
if (value_ == kPassed) return Duration::min();
return value_.time_since_epoch() - CoarseClock::now().time_since_epoch();
}
void Deadline::OnDurationOverflow(std::chrono::duration<double> incoming_duration) {
LOG_TRACE() << "Adding duration " << incoming_duration.count()
<< "s would have overflown deadline, so we replace it with "
<< "unreachable deadline" << logging::LogExtra::Stacktrace();
}
} // namespace engine
USERVER_NAMESPACE_END