/Users/deen/code/yugabyte-db/src/yb/util/ntp_clock.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/util/ntp_clock.h" |
15 | | |
16 | | #include "yb/util/result.h" |
17 | | |
18 | | namespace yb { |
19 | | |
20 | | #if !defined(__APPLE__) |
21 | | NtpClock::NtpClock() : impl_(AdjTimeClock()) {} |
22 | | #endif |
23 | | |
24 | 0 | NtpClock::NtpClock(PhysicalClockPtr impl) : impl_(std::move(impl)) {} |
25 | | |
26 | 0 | Result<PhysicalTime> NtpClock::Now() { |
27 | 0 | auto now = VERIFY_RESULT(impl_->Now()); |
28 | 0 | return PhysicalTime{now.time_point - now.max_error, now.max_error}; |
29 | 0 | } |
30 | | |
31 | 0 | MicrosTime NtpClock::MaxGlobalTime(PhysicalTime time) { |
32 | | // time_point is original time_point - max_error, so we add max_error twice here. |
33 | 0 | return time.time_point + time.max_error * 2; |
34 | 0 | } |
35 | | |
36 | 0 | const std::string& NtpClock::Name() { |
37 | 0 | static std::string result("ntp"); |
38 | 0 | return result; |
39 | 0 | } |
40 | | |
41 | | } // namespace yb |