YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/physical_time.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_UTIL_PHYSICAL_TIME_H
15
#define YB_UTIL_PHYSICAL_TIME_H
16
17
#include <functional> // For std::function
18
#include <memory>
19
20
#include <boost/atomic.hpp>
21
22
#include "yb/util/status_fwd.h"
23
24
namespace yb {
25
26
using MicrosTime = uint64_t;
27
28
struct PhysicalTime {
29
  MicrosTime time_point;
30
  MicrosTime max_error;
31
32
  std::string ToString() const;
33
};
34
35
class PhysicalClock {
36
 public:
37
  virtual Result<PhysicalTime> Now() = 0;
38
  virtual MicrosTime MaxGlobalTime(PhysicalTime time) = 0;
39
6.34k
  virtual ~PhysicalClock() {}
40
};
41
42
typedef std::shared_ptr<PhysicalClock> PhysicalClockPtr;
43
typedef std::function<PhysicalClockPtr(const std::string&)> PhysicalClockProvider;
44
45
// Clock with user controlled return values.
46
class MockClock : public PhysicalClock {
47
 public:
48
  Result<PhysicalTime> Now() override;
49
50
2
  MicrosTime MaxGlobalTime(PhysicalTime time) override {
51
2
    return time.time_point;
52
2
  }
53
54
  void Set(const PhysicalTime& value);
55
56
  // Constructs PhysicalClockPtr from this object.
57
  PhysicalClockPtr AsClock();
58
59
  // Constructs PhysicalClockProvider from this object.
60
  PhysicalClockProvider AsProvider();
61
62
 private:
63
  // Set by calls to SetMockClockWallTimeForTests().
64
  // For testing purposes only.
65
  boost::atomic<PhysicalTime> value_{{0, 0}};
66
};
67
68
const PhysicalClockPtr& WallClock();
69
70
#if !defined(__APPLE__)
71
const PhysicalClockPtr& AdjTimeClock();
72
#endif
73
74
} // namespace yb
75
76
#endif // YB_UTIL_PHYSICAL_TIME_H