1*9356374aSAndroid Build Coastguard Worker // Copyright 2017 The Abseil Authors.
2*9356374aSAndroid Build Coastguard Worker //
3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9356374aSAndroid Build Coastguard Worker //
7*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0
8*9356374aSAndroid Build Coastguard Worker //
9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9356374aSAndroid Build Coastguard Worker // limitations under the License.
14*9356374aSAndroid Build Coastguard Worker //
15*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
16*9356374aSAndroid Build Coastguard Worker // File: clock.h
17*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
18*9356374aSAndroid Build Coastguard Worker //
19*9356374aSAndroid Build Coastguard Worker // This header file contains utility functions for working with the system-wide
20*9356374aSAndroid Build Coastguard Worker // realtime clock. For descriptions of the main time abstractions used within
21*9356374aSAndroid Build Coastguard Worker // this header file, consult the time.h header file.
22*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_TIME_CLOCK_H_
23*9356374aSAndroid Build Coastguard Worker #define ABSL_TIME_CLOCK_H_
24*9356374aSAndroid Build Coastguard Worker
25*9356374aSAndroid Build Coastguard Worker #include <cstdint>
26*9356374aSAndroid Build Coastguard Worker
27*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h"
28*9356374aSAndroid Build Coastguard Worker #include "absl/base/macros.h"
29*9356374aSAndroid Build Coastguard Worker #include "absl/time/time.h"
30*9356374aSAndroid Build Coastguard Worker
31*9356374aSAndroid Build Coastguard Worker namespace absl {
32*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN
33*9356374aSAndroid Build Coastguard Worker
34*9356374aSAndroid Build Coastguard Worker // Now()
35*9356374aSAndroid Build Coastguard Worker //
36*9356374aSAndroid Build Coastguard Worker // Returns the current time, expressed as an `absl::Time` absolute time value.
37*9356374aSAndroid Build Coastguard Worker absl::Time Now();
38*9356374aSAndroid Build Coastguard Worker
39*9356374aSAndroid Build Coastguard Worker // GetCurrentTimeNanos()
40*9356374aSAndroid Build Coastguard Worker //
41*9356374aSAndroid Build Coastguard Worker // Returns the current time, expressed as a count of nanoseconds since the Unix
42*9356374aSAndroid Build Coastguard Worker // Epoch (https://en.wikipedia.org/wiki/Unix_time). Prefer `absl::Now()` instead
43*9356374aSAndroid Build Coastguard Worker // for all but the most performance-sensitive cases (i.e. when you are calling
44*9356374aSAndroid Build Coastguard Worker // this function hundreds of thousands of times per second).
45*9356374aSAndroid Build Coastguard Worker int64_t GetCurrentTimeNanos();
46*9356374aSAndroid Build Coastguard Worker
47*9356374aSAndroid Build Coastguard Worker // SleepFor()
48*9356374aSAndroid Build Coastguard Worker //
49*9356374aSAndroid Build Coastguard Worker // Sleeps for the specified duration, expressed as an `absl::Duration`.
50*9356374aSAndroid Build Coastguard Worker //
51*9356374aSAndroid Build Coastguard Worker // Notes:
52*9356374aSAndroid Build Coastguard Worker // * Signal interruptions will not reduce the sleep duration.
53*9356374aSAndroid Build Coastguard Worker // * Returns immediately when passed a nonpositive duration.
54*9356374aSAndroid Build Coastguard Worker void SleepFor(absl::Duration duration);
55*9356374aSAndroid Build Coastguard Worker
56*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END
57*9356374aSAndroid Build Coastguard Worker } // namespace absl
58*9356374aSAndroid Build Coastguard Worker
59*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
60*9356374aSAndroid Build Coastguard Worker // Implementation Details
61*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
62*9356374aSAndroid Build Coastguard Worker
63*9356374aSAndroid Build Coastguard Worker // In some build configurations we pass --detect-odr-violations to the
64*9356374aSAndroid Build Coastguard Worker // gold linker. This causes it to flag weak symbol overrides as ODR
65*9356374aSAndroid Build Coastguard Worker // violations. Because ODR only applies to C++ and not C,
66*9356374aSAndroid Build Coastguard Worker // --detect-odr-violations ignores symbols not mangled with C++ names.
67*9356374aSAndroid Build Coastguard Worker // By changing our extension points to be extern "C", we dodge this
68*9356374aSAndroid Build Coastguard Worker // check.
69*9356374aSAndroid Build Coastguard Worker extern "C" {
70*9356374aSAndroid Build Coastguard Worker ABSL_DLL void ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(
71*9356374aSAndroid Build Coastguard Worker absl::Duration duration);
72*9356374aSAndroid Build Coastguard Worker } // extern "C"
73*9356374aSAndroid Build Coastguard Worker
SleepFor(absl::Duration duration)74*9356374aSAndroid Build Coastguard Worker inline void absl::SleepFor(absl::Duration duration) {
75*9356374aSAndroid Build Coastguard Worker ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(duration);
76*9356374aSAndroid Build Coastguard Worker }
77*9356374aSAndroid Build Coastguard Worker
78*9356374aSAndroid Build Coastguard Worker #endif // ABSL_TIME_CLOCK_H_
79