private.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (c) 2008-2013 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 of Mac OS X. Any applications
  23. * relying on these interfaces WILL break.
  24. */
  25. #ifndef __DISPATCH_PRIVATE__
  26. #define __DISPATCH_PRIVATE__
  27. #ifdef __APPLE__
  28. #include <Availability.h>
  29. #include <os/availability.h>
  30. #include <TargetConditionals.h>
  31. #include <os/base.h>
  32. #elif defined(_WIN32)
  33. #include <os/generic_win_base.h>
  34. #elif defined(__unix__)
  35. #include <os/generic_unix_base.h>
  36. #endif
  37. #if TARGET_OS_MAC
  38. #include <mach/boolean.h>
  39. #include <mach/mach.h>
  40. #include <mach/message.h>
  41. #endif
  42. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  43. #include <unistd.h>
  44. #endif
  45. #if !defined(_WIN32)
  46. #include <pthread.h>
  47. #endif
  48. #if TARGET_OS_MAC
  49. #include <pthread/qos.h>
  50. #endif
  51. #ifndef __DISPATCH_BUILDING_DISPATCH__
  52. #include <dispatch/dispatch.h>
  53. #ifndef __DISPATCH_INDIRECT__
  54. #define __DISPATCH_INDIRECT__
  55. #endif
  56. #include <dispatch/benchmark.h>
  57. #include <dispatch/queue_private.h>
  58. #include <dispatch/workloop_private.h>
  59. #include <dispatch/source_private.h>
  60. #if DISPATCH_MACH_SPI
  61. #include <dispatch/mach_private.h>
  62. #endif // DISPATCH_MACH_SPI
  63. #include <dispatch/data_private.h>
  64. #include <dispatch/io_private.h>
  65. #include <dispatch/layout_private.h>
  66. #include <dispatch/time_private.h>
  67. #undef __DISPATCH_INDIRECT__
  68. #endif /* !__DISPATCH_BUILDING_DISPATCH__ */
  69. // <rdar://problem/9627726> Check that public and private dispatch headers match
  70. #if DISPATCH_API_VERSION != 20180109 // Keep in sync with <dispatch/dispatch.h>
  71. #error "Dispatch header mismatch between /usr/include and /usr/local/include"
  72. #endif
  73. DISPATCH_ASSUME_NONNULL_BEGIN
  74. __BEGIN_DECLS
  75. /*!
  76. * @function _dispatch_is_multithreaded
  77. *
  78. * @abstract
  79. * Returns true if the current process has become multithreaded by the use
  80. * of libdispatch functionality.
  81. *
  82. * @discussion
  83. * This SPI is intended for use by low-level system components that need to
  84. * ensure that they do not make a single-threaded process multithreaded, to
  85. * avoid negatively affecting child processes of a fork (without exec).
  86. *
  87. * Such components must not use any libdispatch functionality if this function
  88. * returns false.
  89. *
  90. * @result
  91. * Boolean indicating whether the process has used libdispatch and become
  92. * multithreaded.
  93. */
  94. API_AVAILABLE(macos(10.8), ios(6.0))
  95. DISPATCH_EXPORT DISPATCH_NOTHROW
  96. bool _dispatch_is_multithreaded(void);
  97. /*!
  98. * @function _dispatch_is_fork_of_multithreaded_parent
  99. *
  100. * @abstract
  101. * Returns true if the current process is a child of a parent process that had
  102. * become multithreaded by the use of libdispatch functionality at the time of
  103. * fork (without exec).
  104. *
  105. * @discussion
  106. * This SPI is intended for use by (rare) low-level system components that need
  107. * to continue working on the child side of a fork (without exec) of a
  108. * multithreaded process.
  109. *
  110. * Such components must not use any libdispatch functionality if this function
  111. * returns true.
  112. *
  113. * @result
  114. * Boolean indicating whether the parent process had used libdispatch and
  115. * become multithreaded at the time of fork.
  116. */
  117. API_AVAILABLE(macos(10.9), ios(7.0))
  118. DISPATCH_EXPORT DISPATCH_NOTHROW
  119. bool _dispatch_is_fork_of_multithreaded_parent(void);
  120. /*!
  121. * @function _dispatch_prohibit_transition_to_multithreaded
  122. *
  123. * @abstract
  124. * Sets a mode that aborts if a program tries to use dispatch.
  125. *
  126. * @discussion
  127. * This SPI is intended for use by programs that know they will use fork() and
  128. * want their children to be able to use dispatch before exec(). Such programs
  129. * should call _dispatch_prohibit_transition_to_multithreaded(true) as early as
  130. * possible, which will cause any use of dispatch API that would make the
  131. * process multithreaded to abort immediately.
  132. *
  133. * Once the program no longer intends to call fork() it can call
  134. * _dispatch_prohibit_transition_to_multithreaded(false).
  135. *
  136. * This status is not inherited by the child process, so if the behavior
  137. * is required after fork, _dispatch_prohibit_transition_to_multithreaded(true)
  138. * should be called manually in the child after fork.
  139. *
  140. * If the program already used dispatch before the guard is enabled, then
  141. * this function will abort immediately.
  142. */
  143. API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
  144. DISPATCH_EXPORT DISPATCH_NOTHROW
  145. void _dispatch_prohibit_transition_to_multithreaded(bool prohibit);
  146. /*
  147. * dispatch_time convenience macros
  148. */
  149. #define _dispatch_time_after_nsec(t) \
  150. dispatch_time(DISPATCH_TIME_NOW, (t))
  151. #define _dispatch_time_after_usec(t) \
  152. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_USEC)
  153. #define _dispatch_time_after_msec(t) \
  154. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_MSEC)
  155. #define _dispatch_time_after_sec(t) \
  156. dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_SEC)
  157. /*
  158. * SPI for CoreFoundation/Foundation ONLY
  159. */
  160. #if TARGET_OS_MAC
  161. #define DISPATCH_COCOA_COMPAT 1
  162. #elif defined(__linux__) || defined(__FreeBSD__) || defined(_WIN32)
  163. #define DISPATCH_COCOA_COMPAT 1
  164. #else
  165. #define DISPATCH_COCOA_COMPAT 0
  166. #endif
  167. #if DISPATCH_COCOA_COMPAT
  168. #define DISPATCH_CF_SPI_VERSION 20160712
  169. #if TARGET_OS_MAC
  170. typedef mach_port_t dispatch_runloop_handle_t;
  171. #elif defined(__linux__) || defined(__FreeBSD__)
  172. typedef int dispatch_runloop_handle_t;
  173. #elif defined(_WIN32)
  174. typedef void *dispatch_runloop_handle_t;
  175. #else
  176. #error "runloop support not implemented on this platform"
  177. #endif
  178. API_AVAILABLE(macos(10.6), ios(4.0))
  179. DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
  180. dispatch_runloop_handle_t
  181. _dispatch_get_main_queue_port_4CF(void);
  182. API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
  183. DISPATCH_EXPORT DISPATCH_NOTHROW
  184. dispatch_runloop_handle_t
  185. _dispatch_get_main_queue_handle_4CF(void);
  186. API_AVAILABLE(macos(10.6), ios(4.0))
  187. DISPATCH_EXPORT DISPATCH_NOTHROW
  188. void
  189. _dispatch_main_queue_callback_4CF(void *_Null_unspecified msg);
  190. API_AVAILABLE(macos(10.9), ios(7.0))
  191. DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
  192. DISPATCH_NOTHROW
  193. dispatch_queue_serial_t
  194. _dispatch_runloop_root_queue_create_4CF(const char *_Nullable label,
  195. unsigned long flags);
  196. API_AVAILABLE(macos(10.9), ios(7.0))
  197. DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
  198. dispatch_runloop_handle_t
  199. _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t queue);
  200. #if TARGET_OS_MAC
  201. API_AVAILABLE(macos(10.13.2), ios(11.2), tvos(11.2), watchos(4.2))
  202. DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
  203. bool
  204. _dispatch_source_will_reenable_kevent_4NW(dispatch_source_t source);
  205. #endif
  206. API_AVAILABLE(macos(10.9), ios(7.0))
  207. DISPATCH_EXPORT DISPATCH_NOTHROW
  208. void
  209. _dispatch_runloop_root_queue_wakeup_4CF(dispatch_queue_t queue);
  210. API_AVAILABLE(macos(10.9), ios(7.0))
  211. DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
  212. bool
  213. _dispatch_runloop_root_queue_perform_4CF(dispatch_queue_t queue);
  214. API_AVAILABLE(macos(10.9), ios(7.0))
  215. DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
  216. void
  217. _dispatch_source_set_runloop_timer_4CF(dispatch_source_t source,
  218. dispatch_time_t start, uint64_t interval, uint64_t leeway);
  219. API_AVAILABLE(macos(10.6), ios(4.0))
  220. DISPATCH_EXPORT
  221. void *_Nonnull (*_Nullable _dispatch_begin_NSAutoReleasePool)(void);
  222. API_AVAILABLE(macos(10.6), ios(4.0))
  223. DISPATCH_EXPORT
  224. void (*_Nullable _dispatch_end_NSAutoReleasePool)(void *);
  225. #endif /* DISPATCH_COCOA_COMPAT */
  226. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  227. DISPATCH_EXPORT DISPATCH_NOTHROW
  228. void
  229. _dispatch_poll_for_events_4launchd(void);
  230. __END_DECLS
  231. DISPATCH_ASSUME_NONNULL_END
  232. #endif // __DISPATCH_PRIVATE__