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.
218 * @constant DISPATCH_VFS_NEARLOWDISK
219 * Filesystem is nearly full (below NEARLOWDISK level).
221 * @constant DISPATCH_VFS_DESIREDDISK
222 * Filesystem has exceeded the DESIREDDISK level
225 DISPATCH_VFS_NOTRESP
= 0x0001,
226 DISPATCH_VFS_NEEDAUTH
= 0x0002,
227 DISPATCH_VFS_LOWDISK
= 0x0004,
228 DISPATCH_VFS_MOUNT
= 0x0008,
229 DISPATCH_VFS_UNMOUNT
= 0x0010,
230 DISPATCH_VFS_DEAD
= 0x0020,
231 DISPATCH_VFS_ASSIST
= 0x0040,
232 DISPATCH_VFS_NOTRESPLOCK
= 0x0080,
233 DISPATCH_VFS_UPDATE
= 0x0100,
234 DISPATCH_VFS_VERYLOWDISK
= 0x0200,
235 DISPATCH_VFS_QUOTA
= 0x1000,
236 DISPATCH_VFS_NEARLOWDISK
= 0x2000,
237 DISPATCH_VFS_DESIREDDISK
= 0x4000,
241 * @enum dispatch_source_timer_flags_t
243 * @constant DISPATCH_TIMER_BACKGROUND
244 * Specifies that the timer is used to trigger low priority maintenance-level
245 * activity and that the system may apply larger minimum leeway values to the
246 * timer in order to align it with other system activity.
248 * @constant DISPATCH_INTERVAL_UI_ANIMATION
249 * Specifies that the interval source is used for UI animation. The unit for
250 * the interval value of such sources is frames (1/60th of a second) and the
251 * leeway is fixed at one frame.
254 DISPATCH_TIMER_BACKGROUND
= 0x2,
255 DISPATCH_INTERVAL_UI_ANIMATION
= 0x20,
259 * @enum dispatch_source_mach_send_flags_t
261 * @constant DISPATCH_MACH_SEND_POSSIBLE
262 * The mach port corresponding to the given send right has space available
263 * for messages. Delivered only once a mach_msg() to that send right with
264 * options MACH_SEND_MSG|MACH_SEND_TIMEOUT|MACH_SEND_NOTIFY has returned
265 * MACH_SEND_TIMED_OUT (and not again until the next such mach_msg() timeout).
266 * NOTE: The source must have registered the send right for monitoring with the
267 * system for such a mach_msg() to arm the send-possible notifcation, so
268 * the initial send attempt must occur from a source registration handler.
271 DISPATCH_MACH_SEND_POSSIBLE
= 0x8,
275 * @enum dispatch_source_proc_flags_t
277 * @constant DISPATCH_PROC_REAP
278 * The process has been reaped by the parent process via wait*().
279 * This flag is deprecated and will be removed in a future release.
282 DISPATCH_PROC_REAP
__OSX_AVAILABLE_BUT_DEPRECATED(
283 __MAC_10_6
, __MAC_10_9
, __IPHONE_4_0
, __IPHONE_7_0
) = 0x10000000,
287 * @enum dispatch_source_vm_flags_t
289 * @constant DISPATCH_VM_PRESSURE
290 * The VM has experienced memory pressure.
294 DISPATCH_VM_PRESSURE
__OSX_AVAILABLE_BUT_DEPRECATED_MSG(
295 __MAC_10_7
, __MAC_10_10
, __IPHONE_4_3
, __IPHONE_8_0
,
296 "Use DISPATCH_MEMORYPRESSURE_WARN instead") = 0x80000000,
300 * @typedef dispatch_source_memorypressure_flags_t
301 * Type of dispatch_source_memorypressure flags
303 * @constant DISPATCH_MEMORYPRESSURE_LOW_SWAP
304 * The system's memory pressure state has entered the "low swap" condition.
305 * Restricted to the root user.
308 DISPATCH_MEMORYPRESSURE_LOW_SWAP
309 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
) = 0x08,
313 * @enum dispatch_source_memorystatus_flags_t
314 * @warning Deprecated, see DISPATCH_MEMORYPRESSURE_*
317 DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL
318 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
319 __IOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
320 __TVOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
321 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_NORMAL instead")
323 DISPATCH_MEMORYSTATUS_PRESSURE_WARN
324 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
325 __IOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
326 __TVOS_DEPRECATED(6.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
327 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_WARN instead")
329 DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL
330 __OSX_DEPRECATED(10.9, 10.12, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
331 __IOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
332 __TVOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
333 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_CRITICAL instead")
335 DISPATCH_MEMORYSTATUS_LOW_SWAP
336 __OSX_DEPRECATED(10.10, 10.12, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
337 __IOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
338 __TVOS_DEPRECATED(8.0, 10.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
339 __WATCHOS_DEPRECATED(1.0, 3.0, "Use DISPATCH_MEMORYPRESSURE_LOW_SWAP instead")
344 * @typedef dispatch_source_memorypressure_flags_t
345 * Type of dispatch_source_memorypressure flags
347 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
348 * The memory of the process has crossed 80% of its high watermark limit.
350 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
351 * The memory of the process has reached 100% of its high watermark limit.
354 DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
355 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
356 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0) = 0x10,
358 DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
359 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
360 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0) = 0x20,
367 * @function dispatch_source_cancel_and_wait
370 * Synchronously cancel the dispatch source, preventing any further invocation
371 * of its event handler block.
374 * Cancellation prevents any further invocation of handler blocks for the
375 * specified dispatch source, but does not interrupt a handler block that is
376 * already in progress.
378 * When this function returns, any handler block that may have been in progress
379 * has returned, the specified source has been unregistered and it is safe to
380 * reclaim any system resource (such as file descriptors or mach ports) that
381 * the specified source was monitoring.
383 * If the specified dispatch source is inactive, it will be activated as a side
384 * effect of calling this function.
386 * It is possible to call this function from several threads concurrently,
387 * and it is the responsibility of the callers to synchronize reclaiming the
388 * associated system resources.
390 * This function is not subject to priority inversion when it is waiting on
391 * a handler block still in progress, unlike patterns based on waiting on
392 * a dispatch semaphore or a dispatch group signaled (or left) from the source
395 * This function must not be called if the specified source has a cancel
396 * handler set, or from the context of its handler blocks.
398 * This function must not be called from the context of the target queue of
399 * the specified source or from any queue that synchronizes with it. Note that
400 * calling dispatch_source_cancel() from such a context already guarantees
401 * that no handler is in progress, and that no new event will be delivered.
403 * This function must not be called on sources suspended with an explicit
404 * call to dispatch_suspend(), or being concurrently activated on another
408 * The dispatch source to be canceled.
409 * The result of passing NULL in this parameter is undefined.
411 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
412 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0)
413 DISPATCH_EXPORT DISPATCH_NOTHROW
415 dispatch_source_cancel_and_wait(dispatch_source_t source
);
418 * @typedef dispatch_timer_aggregate_t
421 * Dispatch timer aggregates are sets of related timers.
423 DISPATCH_DECL(dispatch_timer_aggregate
);
426 * @function dispatch_timer_aggregate_create
429 * Creates a new dispatch timer aggregate.
432 * A dispatch timer aggregate is a set of related timers whose overall timing
433 * parameters can be queried.
435 * Timers are added to an aggregate when a timer source is created with type
436 * DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE.
439 * The newly created dispatch timer aggregate.
441 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
442 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
444 dispatch_timer_aggregate_t
445 dispatch_timer_aggregate_create(void);
448 * @function dispatch_timer_aggregate_get_delay
451 * Retrieves the delay until a timer in the given aggregate will next fire.
454 * The dispatch timer aggregate to query.
457 * Optional pointer to a variable filled with the leeway (in ns) that will be
458 * applied to the return value. May be NULL.
461 * Delay in ns from now.
463 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
464 DISPATCH_EXPORT DISPATCH_NOTHROW
466 dispatch_timer_aggregate_get_delay(dispatch_timer_aggregate_t aggregate
,
467 uint64_t *_Nullable leeway_ptr
);
469 #if __has_include(<mach/mach.h>)
471 * @typedef dispatch_mig_callback_t
474 * The signature of a function that handles Mach message delivery and response.
476 typedef boolean_t (*dispatch_mig_callback_t
)(mach_msg_header_t
*message
,
477 mach_msg_header_t
*reply
);
479 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
480 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
482 dispatch_mig_server(dispatch_source_t ds
, size_t maxmsgsz
,
483 dispatch_mig_callback_t callback
);
486 * @function dispatch_mach_msg_get_context
489 * Extract the context pointer from a mach message trailer.
491 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
492 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
495 dispatch_mach_msg_get_context(mach_msg_header_t
*msg
);
500 DISPATCH_ASSUME_NONNULL_END