You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

clock.h 2.8 kB

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