-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathcached_time_source_impl.h
37 lines (29 loc) · 1.1 KB
/
cached_time_source_impl.h
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
#pragma once
#include <cstdint>
#include "envoy/common/time.h"
#include "envoy/event/dispatcher.h"
namespace Nighthawk {
/**
* Time source which caches monotonic time. Intended for usage accross components to get a
* consistent view of what "now" is during a single event loop cycle accross components. Minimizes
* system calls to get the monotonic clock. updateApproximateMonotonicTime() must be explicitly
* called on the associated dispatcher to update cached time.
*/
class CachedTimeSourceImpl : public Envoy::TimeSource {
public:
/**
* @param dispatcher Used to source/update cached monotonic time.
*/
CachedTimeSourceImpl(Envoy::Event::Dispatcher& dispatcher) : dispatcher_(dispatcher) {}
/**
* @return Envoy::SystemTime current system time.
*/
Envoy::SystemTime systemTime() override { return dispatcher_.timeSource().systemTime(); };
/**
* @return Envoy::MonotonicTime cached monotonic time.
*/
Envoy::MonotonicTime monotonicTime() override { return dispatcher_.approximateMonotonicTime(); };
private:
Envoy::Event::Dispatcher& dispatcher_;
};
} // namespace Nighthawk