/Users/deen/code/yugabyte-db/src/yb/common/clock.h
Line | Count | Source |
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 | | #ifndef YB_COMMON_CLOCK_H |
15 | | #define YB_COMMON_CLOCK_H |
16 | | |
17 | | #include "yb/gutil/ref_counted.h" |
18 | | #include "yb/common/hybrid_time.h" |
19 | | |
20 | | namespace yb { |
21 | | |
22 | | typedef std::pair<HybridTime, HybridTime> HybridTimeRange; |
23 | | |
24 | | class ClockBase : public RefCountedThreadSafe<ClockBase> { |
25 | | public: |
26 | | // Obtains a new transaction timestamp corresponding to the current instant. |
27 | 196M | HybridTime Now() { return NowRange().first; } |
28 | | |
29 | | // Obtains the hybrid_time corresponding to the current time, |
30 | | // that is maximally possible in cluster. |
31 | 296k | HybridTime MaxGlobalNow() { return NowRange().second; } |
32 | | |
33 | | virtual HybridTimeRange NowRange() = 0; |
34 | | |
35 | | virtual void Update(const HybridTime& to_update) = 0; |
36 | | |
37 | 6.95k | virtual ~ClockBase() {} |
38 | | }; |
39 | | |
40 | | // Returns time after wait. |
41 | | // Returns error on timeout. |
42 | | Result<HybridTime> WaitUntil(ClockBase* clock, HybridTime hybrid_time, CoarseTimePoint deadline); |
43 | | |
44 | | } // namespace yb |
45 | | |
46 | | #endif // YB_COMMON_CLOCK_H |