blob: 27764a922d5e3811f48f1f02e7bb7e5142963f91 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001// Copyright 2017 The Abseil Authors.
2//
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
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
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.
14//
15// -----------------------------------------------------------------------------
16// File: clock.h
17// -----------------------------------------------------------------------------
18//
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_
24
25#include "absl/base/macros.h"
26#include "absl/time/time.h"
27
28namespace absl {
Austin Schuhb4691e92020-12-31 12:37:18 -080029ABSL_NAMESPACE_BEGIN
Austin Schuh36244a12019-09-21 17:52:38 -070030
31// Now()
32//
33// Returns the current time, expressed as an `absl::Time` absolute time value.
34absl::Time Now();
35
36// GetCurrentTimeNanos()
37//
38// Returns the current time, expressed as a count of nanoseconds since the Unix
39// Epoch (https://en.wikipedia.org/wiki/Unix_time). Prefer `absl::Now()` instead
40// for all but the most performance-sensitive cases (i.e. when you are calling
41// this function hundreds of thousands of times per second).
42int64_t GetCurrentTimeNanos();
43
44// SleepFor()
45//
46// Sleeps for the specified duration, expressed as an `absl::Duration`.
47//
48// Notes:
49// * Signal interruptions will not reduce the sleep duration.
50// * Returns immediately when passed a nonpositive duration.
51void SleepFor(absl::Duration duration);
52
Austin Schuhb4691e92020-12-31 12:37:18 -080053ABSL_NAMESPACE_END
Austin Schuh36244a12019-09-21 17:52:38 -070054} // namespace absl
55
56// -----------------------------------------------------------------------------
57// Implementation Details
58// -----------------------------------------------------------------------------
59
60// In some build configurations we pass --detect-odr-violations to the
61// gold linker. This causes it to flag weak symbol overrides as ODR
62// violations. Because ODR only applies to C++ and not C,
63// --detect-odr-violations ignores symbols not mangled with C++ names.
64// By changing our extension points to be extern "C", we dodge this
65// check.
66extern "C" {
67void AbslInternalSleepFor(absl::Duration duration);
68} // extern "C"
69
70inline void absl::SleepFor(absl::Duration duration) {
71 AbslInternalSleepFor(duration);
72}
73
74#endif // ABSL_TIME_CLOCK_H_