clock.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 The Crashpad Authors. All rights reserved.
  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. // http://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. #ifndef CRASHPAD_UTIL_MISC_CLOCK_H_
  15. #define CRASHPAD_UTIL_MISC_CLOCK_H_
  16. #include <stdint.h>
  17. #include "build/build_config.h"
  18. namespace crashpad {
  19. //! \brief Returns the value of the system’s monotonic clock.
  20. //!
  21. //! The monotonic clock is a tick counter whose epoch is unspecified. It is a
  22. //! monotonically-increasing clock that cannot be set, and never jumps backwards
  23. //! on a running system. The monotonic clock may stop while the system is
  24. //! sleeping, and it may be reset when the system starts up. This clock is
  25. //! suitable for computing durations of events. Subject to the underlying
  26. //! clock’s resolution, successive calls to this function will result in a
  27. //! series of increasing values.
  28. //!
  29. //! \return The value of the system’s monotonic clock, in nanoseconds.
  30. uint64_t ClockMonotonicNanoseconds();
  31. //! \brief Sleeps for the specified duration.
  32. //!
  33. //! \param[in] nanoseconds The number of nanoseconds to sleep. The actual sleep
  34. //! may be slightly longer due to latencies and timer resolution.
  35. //!
  36. //! On POSIX, this function is resilient against the underlying `nanosleep()`
  37. //! system call being interrupted by a signal.
  38. void SleepNanoseconds(uint64_t nanoseconds);
  39. } // namespace crashpad
  40. #endif // CRASHPAD_UTIL_MISC_CLOCK_H_