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