00001 // Copyright 2017 The Abseil Authors. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // https://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 // 00015 // ----------------------------------------------------------------------------- 00016 // File: clock.h 00017 // ----------------------------------------------------------------------------- 00018 // 00019 // This header file contains utility functions for working with the system-wide 00020 // realtime clock. For descriptions of the main time abstractions used within 00021 // this header file, consult the time.h header file. 00022 #ifndef ABSL_TIME_CLOCK_H_ 00023 #define ABSL_TIME_CLOCK_H_ 00024 00025 #include "absl/base/macros.h" 00026 #include "absl/time/time.h" 00027 00028 namespace absl { 00029 00030 // Now() 00031 // 00032 // Returns the current time, expressed as an `absl::Time` absolute time value. 00033 absl::Time Now(); 00034 00035 // GetCurrentTimeNanos() 00036 // 00037 // Returns the current time, expressed as a count of nanoseconds since the Unix 00038 // Epoch (https://en.wikipedia.org/wiki/Unix_time). Prefer `absl::Now()` instead 00039 // for all but the most performance-sensitive cases (i.e. when you are calling 00040 // this function hundreds of thousands of times per second). 00041 int64_t GetCurrentTimeNanos(); 00042 00043 // SleepFor() 00044 // 00045 // Sleeps for the specified duration, expressed as an `absl::Duration`. 00046 // 00047 // Notes: 00048 // * Signal interruptions will not reduce the sleep duration. 00049 // * Returns immediately when passed a nonpositive duration. 00050 void SleepFor(absl::Duration duration); 00051 00052 } // namespace absl 00053 00054 // ----------------------------------------------------------------------------- 00055 // Implementation Details 00056 // ----------------------------------------------------------------------------- 00057 00058 // In some build configurations we pass --detect-odr-violations to the 00059 // gold linker. This causes it to flag weak symbol overrides as ODR 00060 // violations. Because ODR only applies to C++ and not C, 00061 // --detect-odr-violations ignores symbols not mangled with C++ names. 00062 // By changing our extension points to be extern "C", we dodge this 00063 // check. 00064 extern "C" { 00065 void AbslInternalSleepFor(absl::Duration duration); 00066 } // extern "C" 00067 00068 inline void absl::SleepFor(absl::Duration duration) { 00069 AbslInternalSleepFor(duration); 00070 } 00071 00072 #endif // ABSL_TIME_CLOCK_H_