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