time_private.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 20017 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. /*
  21. * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
  22. * which are subject to change in future releases. Any applications relying on
  23. * these interfaces WILL break.
  24. */
  25. #ifndef __DISPATCH_TIME_PRIVATE__
  26. #define __DISPATCH_TIME_PRIVATE__
  27. #ifndef __DISPATCH_INDIRECT__
  28. #error "Please #include <dispatch/private.h> instead of this file directly."
  29. #include <dispatch/base.h> // for HeaderDoc
  30. #endif
  31. /*
  32. * @constant DISPATCH_MONOTONICTIME_NOW
  33. * A dispatch_time_t value that corresponds to the current value of the
  34. * platform's monotonic clock. On Apple platforms, this clock is based on
  35. * mach_continuous_time(). Use this value with the dispatch_time() function to
  36. * derive a time value for a timer in monotonic time (i.e. a timer that
  37. * continues to tick while the system is asleep). For example:
  38. *
  39. * dispatch_time_t t = dispatch_time(DISPATCH_MONOTONICTIME_NOW,5*NSEC_PER_SEC);
  40. * dispatch_source_t ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,
  41. * 0, 0, q);
  42. * dispatch_source_set_event_handler(ds, ^{ ... });
  43. * dispatch_source_set_timer(ds, t, 10 * NSEC_PER_SEC, 0);
  44. * dispatch_activate(ds);
  45. */
  46. enum {
  47. DISPATCH_MONOTONICTIME_NOW DISPATCH_ENUM_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = (1ull << 63)
  48. };
  49. #ifdef __APPLE__
  50. // Helper macros for up time, montonic time and wall time.
  51. #define _dispatch_uptime_after_nsec(t) \
  52. dispatch_time(DISPATCH_TIME_NOW, (t))
  53. #define _dispatch_uptime_after_usec(t) \
  54. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_USEC)
  55. #define _dispatch_uptime_after_msec(t) \
  56. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_MSEC)
  57. #define _dispatch_uptime_after_sec(t) \
  58. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_SEC)
  59. #define _dispatch_monotonictime_after_nsec(t) \
  60. dispatch_time(DISPATCH_MONOTONICTIME_NOW, (t))
  61. #define _dispatch_monotonictime_after_usec(t) \
  62. dispatch_time(DISPATCH_MONOTONICTIME_NOW, (t) * NSEC_PER_USEC)
  63. #define _dispatch_monotonictime_after_msec(t) \
  64. dispatch_time(DISPATCH_MONOTONICTIME_NOW, (t) * NSEC_PER_MSEC)
  65. #define _dispatch_monotonictime_after_sec(t) \
  66. dispatch_time(DISPATCH_MONOTONICTIME_NOW, (t) * NSEC_PER_SEC)
  67. #define _dispatch_walltime_after_nsec(t) \
  68. dispatch_time(DISPATCH_WALLTIME_NOW, (t))
  69. #define _dispatch_walltime_after_usec(t) \
  70. dispatch_time(DISPATCH_WALLTIME_NOW, (t) * NSEC_PER_USEC)
  71. #define _dispatch_walltime_after_msec(t) \
  72. dispatch_time(DISPATCH_WALLTIME_NOW, (t) * NSEC_PER_MSEC)
  73. #define _dispatch_walltime_after_sec(t) \
  74. dispatch_time(DISPATCH_WALLTIME_NOW, (t) * NSEC_PER_SEC)
  75. #endif // __APPLE__
  76. #endif