• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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/config.h"
26 #include "absl/base/macros.h"
27 #include "absl/time/time.h"
28 
29 namespace absl {
30 ABSL_NAMESPACE_BEGIN
31 
32 // Now()
33 //
34 // Returns the current time, expressed as an `absl::Time` absolute time value.
35 absl::Time Now();
36 
37 // GetCurrentTimeNanos()
38 //
39 // Returns the current time, expressed as a count of nanoseconds since the Unix
40 // Epoch (https://en.wikipedia.org/wiki/Unix_time). Prefer `absl::Now()` instead
41 // for all but the most performance-sensitive cases (i.e. when you are calling
42 // this function hundreds of thousands of times per second).
43 int64_t GetCurrentTimeNanos();
44 
45 // SleepFor()
46 //
47 // Sleeps for the specified duration, expressed as an `absl::Duration`.
48 //
49 // Notes:
50 // * Signal interruptions will not reduce the sleep duration.
51 // * Returns immediately when passed a nonpositive duration.
52 void SleepFor(absl::Duration duration);
53 
54 ABSL_NAMESPACE_END
55 }  // namespace absl
56 
57 // -----------------------------------------------------------------------------
58 // Implementation Details
59 // -----------------------------------------------------------------------------
60 
61 // In some build configurations we pass --detect-odr-violations to the
62 // gold linker.  This causes it to flag weak symbol overrides as ODR
63 // violations.  Because ODR only applies to C++ and not C,
64 // --detect-odr-violations ignores symbols not mangled with C++ names.
65 // By changing our extension points to be extern "C", we dodge this
66 // check.
67 extern "C" {
68 ABSL_DLL void ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(
69     absl::Duration duration);
70 }  // extern "C"
71 
SleepFor(absl::Duration duration)72 inline void absl::SleepFor(absl::Duration duration) {
73   ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(duration);
74 }
75 
76 #endif  // ABSL_TIME_CLOCK_H_
77