/src/gbmcweb/tlbmc/time/clock.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2020 Google LLC |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #include "time/clock.h" |
18 | | |
19 | | #include "absl/time/clock.h" |
20 | | #include "absl/time/time.h" |
21 | | |
22 | | namespace ecclesia { |
23 | | namespace { |
24 | | |
25 | | // The abseil clock functions are already thread-safe and this clock doesn't |
26 | | // have any state of its own, so it is also thread-safe. If any state is later |
27 | | // added to this object then care must be taken to preserve thread-safety. |
28 | | class RealClock : public Clock { |
29 | | public: |
30 | 8.16k | absl::Time Now() const override { return absl::Now(); } |
31 | 0 | void Sleep(absl::Duration d) override { absl::SleepFor(d); } |
32 | | }; |
33 | | |
34 | | } // namespace |
35 | | |
36 | 2.04k | Clock* Clock::RealClock() { |
37 | 2.04k | static Clock& real_clock = *(new class RealClock()); |
38 | 2.04k | return &real_clock; |
39 | 2.04k | } |
40 | | |
41 | | } // namespace ecclesia |