2 * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
27 #ifndef __DISPATCH_SOURCE_PRIVATE__
28 #define __DISPATCH_SOURCE_PRIVATE__
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/private.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
35 DISPATCH_ASSUME_NONNULL_BEGIN
40 * @const DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE
41 * @discussion A dispatch timer source that is part of a timer aggregate.
42 * The handle is the dispatch timer aggregate object.
43 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
45 #define DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE \
46 (&_dispatch_source_type_timer_with_aggregate)
47 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
48 DISPATCH_SOURCE_TYPE_DECL(timer_with_aggregate
);
51 * @const DISPATCH_SOURCE_TYPE_INTERVAL
52 * @discussion A dispatch source that submits the event handler block at a
53 * specified time interval, phase-aligned with all other interval sources on
54 * the system that have the same interval value.
56 * The initial submission of the event handler will occur at some point during
57 * the first time interval after the source is created (assuming the source is
58 * resumed at that time).
60 * By default, the unit for the interval value is milliseconds and the leeway
61 * (maximum amount of time any individual handler submission may be deferred to
62 * align with other system activity) for the source is fixed at interval/2.
64 * If the DISPATCH_INTERVAL_UI_ANIMATION flag is specified, the unit for the
65 * interval value is animation frames (1/60th of a second) and the leeway is
68 * The handle is the interval value in milliseconds or frames.
69 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
71 #define DISPATCH_SOURCE_TYPE_INTERVAL (&_dispatch_source_type_interval)
72 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
73 DISPATCH_SOURCE_TYPE_DECL(interval
);
76 * @const DISPATCH_SOURCE_TYPE_VFS
77 * @discussion Apple-internal dispatch source that monitors for vfs events
78 * defined by dispatch_vfs_flags_t.
79 * The handle is a process identifier (pid_t).
81 #define DISPATCH_SOURCE_TYPE_VFS (&_dispatch_source_type_vfs)
82 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
83 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_vfs
;
86 * @const DISPATCH_SOURCE_TYPE_VM
87 * @discussion A dispatch source that monitors virtual memory
88 * The mask is a mask of desired events from dispatch_source_vm_flags_t.
89 * This type is deprecated, use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead.
91 #define DISPATCH_SOURCE_TYPE_VM (&_dispatch_source_type_vm)
92 __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_7
, __MAC_10_10
, __IPHONE_4_3
,
93 __IPHONE_8_0
, "Use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead")
94 DISPATCH_LINUX_UNAVAILABLE()
95 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_vm
;
98 * @const DISPATCH_SOURCE_TYPE_MEMORYSTATUS
99 * @discussion A dispatch source that monitors memory status
100 * The mask is a mask of desired events from
101 * dispatch_source_memorystatus_flags_t.
103 #define DISPATCH_SOURCE_TYPE_MEMORYSTATUS (&_dispatch_source_type_memorystatus)
104 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead")
105 __IOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead")
106 __TVOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead")
107 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead")
108 DISPATCH_LINUX_UNAVAILABLE()
109 DISPATCH_EXPORT
const struct dispatch_source_type_s
110 _dispatch_source_type_memorystatus
;
113 * @const DISPATCH_SOURCE_TYPE_SOCK
114 * @discussion A dispatch source that monitors events on socket state changes.
116 #define DISPATCH_SOURCE_TYPE_SOCK (&_dispatch_source_type_sock)
117 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
) DISPATCH_LINUX_UNAVAILABLE()
118 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_sock
;
123 * @enum dispatch_source_sock_flags_t
125 * @constant DISPATCH_SOCK_CONNRESET
128 * @constant DISPATCH_SOCK_READCLOSED
129 * Read side is shutdown
131 * @constant DISPATCH_SOCK_WRITECLOSED
132 * Write side is shutdown
134 * @constant DISPATCH_SOCK_TIMEOUT
135 * Timeout: rexmt, keep-alive or persist
137 * @constant DISPATCH_SOCK_NOSRCADDR
138 * Source address not available
140 * @constant DISPATCH_SOCK_IFDENIED
141 * Interface denied connection
143 * @constant DISPATCH_SOCK_SUSPEND
144 * Output queue suspended
146 * @constant DISPATCH_SOCK_RESUME
147 * Output queue resumed
149 * @constant DISPATCH_SOCK_KEEPALIVE
150 * TCP Keepalive received
152 * @constant DISPATCH_SOCK_CONNECTED
153 * Socket is connected
155 * @constant DISPATCH_SOCK_DISCONNECTED
156 * Socket is disconnected
158 * @constant DISPATCH_SOCK_CONNINFO_UPDATED
159 * Connection info was updated
161 * @constant DISPATCH_SOCK_NOTIFY_ACK
162 * Notify acknowledgement
165 DISPATCH_SOCK_CONNRESET
= 0x00000001,
166 DISPATCH_SOCK_READCLOSED
= 0x00000002,
167 DISPATCH_SOCK_WRITECLOSED
= 0x00000004,
168 DISPATCH_SOCK_TIMEOUT
= 0x00000008,
169 DISPATCH_SOCK_NOSRCADDR
= 0x00000010,
170 DISPATCH_SOCK_IFDENIED
= 0x00000020,
171 DISPATCH_SOCK_SUSPEND
= 0x00000040,
172 DISPATCH_SOCK_RESUME
= 0x00000080,
173 DISPATCH_SOCK_KEEPALIVE
= 0x00000100,
174 DISPATCH_SOCK_ADAPTIVE_WTIMO
= 0x00000200,
175 DISPATCH_SOCK_ADAPTIVE_RTIMO
= 0x00000400,
176 DISPATCH_SOCK_CONNECTED
= 0x00000800,
177 DISPATCH_SOCK_DISCONNECTED
= 0x00001000,
178 DISPATCH_SOCK_CONNINFO_UPDATED
= 0x00002000,
179 DISPATCH_SOCK_NOTIFY_ACK
= 0x00004000,
183 * @enum dispatch_source_vfs_flags_t
185 * @constant DISPATCH_VFS_NOTRESP
188 * @constant DISPATCH_VFS_NEEDAUTH
191 * @constant DISPATCH_VFS_LOWDISK
192 * We're low on space.
194 * @constant DISPATCH_VFS_MOUNT
195 * New filesystem arrived.
197 * @constant DISPATCH_VFS_UNMOUNT
198 * Filesystem has left.
200 * @constant DISPATCH_VFS_DEAD
201 * Filesystem is dead, needs force unmount.
203 * @constant DISPATCH_VFS_ASSIST
204 * Filesystem needs assistance from external program.
206 * @constant DISPATCH_VFS_NOTRESPLOCK
209 * @constant DISPATCH_VFS_UPDATE
210 * Filesystem information has changed.
212 * @constant DISPATCH_VFS_VERYLOWDISK
213 * File system has *very* little disk space left.
215 * @constant DISPATCH_VFS_QUOTA
216 * We hit a user quota (quotactl) for this filesystem.
219 DISPATCH_VFS_NOTRESP
= 0x0001,
220 DISPATCH_VFS_NEEDAUTH
= 0x0002,
221 DISPATCH_VFS_LOWDISK
= 0x0004,
222 DISPATCH_VFS_MOUNT
= 0x0008,
223 DISPATCH_VFS_UNMOUNT
= 0x0010,
224 DISPATCH_VFS_DEAD
= 0x0020,
225 DISPATCH_VFS_ASSIST
= 0x0040,
226 DISPATCH_VFS_NOTRESPLOCK
= 0x0080,
227 DISPATCH_VFS_UPDATE
= 0x0100,
228 DISPATCH_VFS_VERYLOWDISK
= 0x0200,
229 DISPATCH_VFS_QUOTA
= 0x1000,
233 * @enum dispatch_source_timer_flags_t
235 * @constant DISPATCH_TIMER_BACKGROUND
236 * Specifies that the timer is used to trigger low priority maintenance-level
237 * activity and that the system may apply larger minimum leeway values to the
238 * timer in order to align it with other system activity.
240 * @constant DISPATCH_INTERVAL_UI_ANIMATION
241 * Specifies that the interval source is used for UI animation. The unit for
242 * the interval value of such sources is frames (1/60th of a second) and the
243 * leeway is fixed at one frame.
246 DISPATCH_TIMER_BACKGROUND
= 0x2,
247 DISPATCH_INTERVAL_UI_ANIMATION
= 0x20,
251 * @enum dispatch_source_mach_send_flags_t
253 * @constant DISPATCH_MACH_SEND_POSSIBLE
254 * The mach port corresponding to the given send right has space available
255 * for messages. Delivered only once a mach_msg() to that send right with
256 * options MACH_SEND_MSG|MACH_SEND_TIMEOUT|MACH_SEND_NOTIFY has returned
257 * MACH_SEND_TIMED_OUT (and not again until the next such mach_msg() timeout).
258 * NOTE: The source must have registered the send right for monitoring with the
259 * system for such a mach_msg() to arm the send-possible notifcation, so
260 * the initial send attempt must occur from a source registration handler.
263 DISPATCH_MACH_SEND_POSSIBLE
= 0x8,
267 * @enum dispatch_source_proc_flags_t
269 * @constant DISPATCH_PROC_REAP
270 * The process has been reaped by the parent process via wait*().
271 * This flag is deprecated and will be removed in a future release.
274 DISPATCH_PROC_REAP
__OSX_AVAILABLE_BUT_DEPRECATED(
275 __MAC_10_6
, __MAC_10_9
, __IPHONE_4_0
, __IPHONE_7_0
) = 0x10000000,
279 * @enum dispatch_source_vm_flags_t
281 * @constant DISPATCH_VM_PRESSURE
282 * The VM has experienced memory pressure.
286 DISPATCH_VM_PRESSURE
__OSX_AVAILABLE_BUT_DEPRECATED_MSG(
287 __MAC_10_7
, __MAC_10_10
, __IPHONE_4_3
, __IPHONE_8_0
,
288 "Use DISPATCH_MEMORYPRESSURE_WARN instead") = 0x80000000,
292 * @typedef dispatch_source_memorypressure_flags_t
293 * Type of dispatch_source_memorypressure flags
295 * @constant DISPATCH_MEMORYPRESSURE_LOW_SWAP
296 * The system's memory pressure state has entered the "low swap" condition.
297 * Restricted to the root user.
300 DISPATCH_MEMORYPRESSURE_LOW_SWAP
301 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
) = 0x08,
305 * @enum dispatch_source_memorystatus_flags_t
306 * @warning Deprecated, see DISPATCH_MEMORYPRESSURE_*
309 DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL
310 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
311 __IOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
312 __TVOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
313 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
315 DISPATCH_MEMORYSTATUS_PRESSURE_WARN
316 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
317 __IOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
318 __TVOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
319 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
321 DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL
322 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
323 __IOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
324 __TVOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
325 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
327 DISPATCH_MEMORYSTATUS_LOW_SWAP
328 __OSX_DEPRECATED(10.10, 10.12, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
329 __IOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
330 __TVOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
331 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
336 * @typedef dispatch_source_memorypressure_flags_t
337 * Type of dispatch_source_memorypressure flags
339 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
340 * The memory of the process has crossed 80% of its high watermark limit.
342 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
343 * The memory of the process has reached 100% of its high watermark limit.
346 DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
347 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
348 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0) = 0x10,
350 DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
351 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
352 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0) = 0x20,
359 * @function dispatch_source_cancel_and_wait
362 * Synchronously cancel the dispatch source, preventing any further invocation
363 * of its event handler block.
366 * Cancellation prevents any further invocation of handler blocks for the
367 * specified dispatch source, but does not interrupt a handler block that is
368 * already in progress.
370 * When this function returns, any handler block that may have been in progress
371 * has returned, the specified source has been unregistered and it is safe to
372 * reclaim any system resource (such as file descriptors or mach ports) that
373 * the specified source was monitoring.
375 * If the specified dispatch source is inactive, it will be activated as a side
376 * effect of calling this function.
378 * It is possible to call this function from several threads concurrently,
379 * and it is the responsibility of the callers to synchronize reclaiming the
380 * associated system resources.
382 * This function is not subject to priority inversion when it is waiting on
383 * a handler block still in progress, unlike patterns based on waiting on
384 * a dispatch semaphore or a dispatch group signaled (or left) from the source
387 * This function must not be called if the specified source has a cancel
388 * handler set, or from the context of its handler blocks.
390 * This function must not be called from the context of the target queue of
391 * the specified source or from any queue that synchronizes with it. Note that
392 * calling dispatch_source_cancel() from such a context already guarantees
393 * that no handler is in progress, and that no new event will be delivered.
395 * This function must not be called on sources suspended with an explicit
396 * call to dispatch_suspend(), or being concurrently activated on another
400 * The dispatch source to be canceled.
401 * The result of passing NULL in this parameter is undefined.
403 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
404 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0)
405 DISPATCH_EXPORT DISPATCH_NOTHROW
407 dispatch_source_cancel_and_wait(dispatch_source_t source
);
410 * @typedef dispatch_timer_aggregate_t
413 * Dispatch timer aggregates are sets of related timers.
415 DISPATCH_DECL(dispatch_timer_aggregate
);
418 * @function dispatch_timer_aggregate_create
421 * Creates a new dispatch timer aggregate.
424 * A dispatch timer aggregate is a set of related timers whose overall timing
425 * parameters can be queried.
427 * Timers are added to an aggregate when a timer source is created with type
428 * DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE.
431 * The newly created dispatch timer aggregate.
433 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
434 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
436 dispatch_timer_aggregate_t
437 dispatch_timer_aggregate_create(void);
440 * @function dispatch_timer_aggregate_get_delay
443 * Retrieves the delay until a timer in the given aggregate will next fire.
446 * The dispatch timer aggregate to query.
449 * Optional pointer to a variable filled with the leeway (in ns) that will be
450 * applied to the return value. May be NULL.
453 * Delay in ns from now.
455 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
456 DISPATCH_EXPORT DISPATCH_NOTHROW
458 dispatch_timer_aggregate_get_delay(dispatch_timer_aggregate_t aggregate
,
459 uint64_t *_Nullable leeway_ptr
);
461 #if __has_include(<mach/mach.h>)
463 * @typedef dispatch_mig_callback_t
466 * The signature of a function that handles Mach message delivery and response.
468 typedef boolean_t (*dispatch_mig_callback_t
)(mach_msg_header_t
*message
,
469 mach_msg_header_t
*reply
);
471 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
472 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
474 dispatch_mig_server(dispatch_source_t ds
, size_t maxmsgsz
,
475 dispatch_mig_callback_t callback
);
478 * @function dispatch_mach_msg_get_context
481 * Extract the context pointer from a mach message trailer.
483 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
484 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
487 dispatch_mach_msg_get_context(mach_msg_header_t
*msg
);
492 DISPATCH_ASSUME_NONNULL_END