/Users/deen/code/yugabyte-db/src/yb/common/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/common/clock.h" |
15 | | |
16 | | #include <thread> |
17 | | |
18 | | #include "yb/util/result.h" |
19 | | #include "yb/util/status_format.h" |
20 | | |
21 | | using namespace std::literals; |
22 | | |
23 | | DEFINE_uint64(wait_hybrid_time_sleep_interval_us, 10000, |
24 | | "Sleep interval in microseconds that will be used while waiting for specific " |
25 | | "hybrid time."); |
26 | | |
27 | | namespace yb { |
28 | | |
29 | 73.4M | Result<HybridTime> WaitUntil(ClockBase* clock, HybridTime hybrid_time, CoarseTimePoint deadline) { |
30 | 73.4M | auto ht_now = clock->Now(); |
31 | 73.4M | while (ht_now < hybrid_time) { |
32 | 524 | if (CoarseMonoClock::now() > deadline) { |
33 | 0 | return STATUS_FORMAT(TimedOut, "Timed out waiting for $0, now $1", deadline, ht_now); |
34 | 0 | } |
35 | 524 | auto delta_micros = hybrid_time.GetPhysicalValueMicros() - ht_now.GetPhysicalValueMicros(); |
36 | 524 | std::this_thread::sleep_for( |
37 | 524 | std::max(FLAGS_wait_hybrid_time_sleep_interval_us, delta_micros) * 1us); |
38 | 524 | ht_now = clock->Now(); |
39 | 524 | } |
40 | | |
41 | 73.4M | return ht_now; |
42 | 73.4M | } |
43 | | |
44 | | } // namespace yb |