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
36 * @const DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE
37 * @discussion A dispatch timer source that is part of a timer aggregate.
38 * The handle is the dispatch timer aggregate object.
39 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
41 #define DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE \
42 (&_dispatch_source_type_timer_with_aggregate)
43 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
44 DISPATCH_SOURCE_TYPE_DECL(timer_with_aggregate
);
47 * @const DISPATCH_SOURCE_TYPE_INTERVAL
48 * @discussion A dispatch source that submits the event handler block at a
49 * specified time interval, phase-aligned with all other interval sources on
50 * the system that have the same interval value.
52 * The initial submission of the event handler will occur at some point during
53 * the first time interval after the source is created (assuming the source is
54 * resumed at that time).
56 * By default, the unit for the interval value is milliseconds and the leeway
57 * (maximum amount of time any individual handler submission may be deferred to
58 * align with other system activity) for the source is fixed at interval/2.
60 * If the DISPATCH_INTERVAL_UI_ANIMATION flag is specified, the unit for the
61 * interval value is animation frames (1/60th of a second) and the leeway is
64 * The handle is the interval value in milliseconds or frames.
65 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
67 #define DISPATCH_SOURCE_TYPE_INTERVAL (&_dispatch_source_type_interval)
68 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
69 DISPATCH_SOURCE_TYPE_DECL(interval
);
72 * @const DISPATCH_SOURCE_TYPE_VFS
73 * @discussion Apple-internal dispatch source that monitors for vfs events
74 * defined by dispatch_vfs_flags_t.
75 * The handle is a process identifier (pid_t).
77 #define DISPATCH_SOURCE_TYPE_VFS (&_dispatch_source_type_vfs)
78 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
79 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_vfs
;
82 * @const DISPATCH_SOURCE_TYPE_VM
83 * @discussion A dispatch source that monitors virtual memory
84 * The mask is a mask of desired events from dispatch_source_vm_flags_t.
86 #define DISPATCH_SOURCE_TYPE_VM (&_dispatch_source_type_vm)
87 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
88 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_vm
;
91 * @const DISPATCH_SOURCE_TYPE_MEMORYSTATUS
92 * @discussion A dispatch source that monitors memory status
93 * The mask is a mask of desired events from
94 * dispatch_source_memorystatus_flags_t.
96 #define DISPATCH_SOURCE_TYPE_MEMORYSTATUS (&_dispatch_source_type_memorystatus)
97 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_6_0
)
98 DISPATCH_EXPORT
const struct dispatch_source_type_s
99 _dispatch_source_type_memorystatus
;
102 * @const DISPATCH_SOURCE_TYPE_SOCK
103 * @discussion A dispatch source that monitors events on socket state changes.
105 #define DISPATCH_SOURCE_TYPE_SOCK (&_dispatch_source_type_sock)
106 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
107 DISPATCH_EXPORT
const struct dispatch_source_type_s _dispatch_source_type_sock
;
110 * @enum dispatch_source_sock_flags_t
112 * @constant DISPATCH_SOCK_CONNRESET
115 * @constant DISPATCH_SOCK_READCLOSED
116 * Read side is shutdown
118 * @constant DISPATCH_SOCK_WRITECLOSED
119 * Write side is shutdown
121 * @constant DISPATCH_SOCK_TIMEOUT
122 * Timeout: rexmt, keep-alive or persist
124 * @constant DISPATCH_SOCK_NOSRCADDR
125 * Source address not available
127 * @constant DISPATCH_SOCK_IFDENIED
128 * Interface denied connection
130 * @constant DISPATCH_SOCK_SUSPEND
131 * Output queue suspended
133 * @constant DISPATCH_SOCK_RESUME
134 * Output queue resumed
136 * @constant DISPATCH_SOCK_KEEPALIVE
137 * TCP Keepalive received
139 * @constant DISPATCH_SOCK_CONNECTED
140 * Socket is connected
142 * @constant DISPATCH_SOCK_DISCONNECTED
143 * Socket is disconnected
145 * @constant DISPATCH_SOCK_CONNINFO_UPDATED
146 * Connection info was updated
149 DISPATCH_SOCK_CONNRESET
= 0x00000001,
150 DISPATCH_SOCK_READCLOSED
= 0x00000002,
151 DISPATCH_SOCK_WRITECLOSED
= 0x00000004,
152 DISPATCH_SOCK_TIMEOUT
= 0x00000008,
153 DISPATCH_SOCK_NOSRCADDR
= 0x00000010,
154 DISPATCH_SOCK_IFDENIED
= 0x00000020,
155 DISPATCH_SOCK_SUSPEND
= 0x00000040,
156 DISPATCH_SOCK_RESUME
= 0x00000080,
157 DISPATCH_SOCK_KEEPALIVE
= 0x00000100,
158 DISPATCH_SOCK_ADAPTIVE_WTIMO
= 0x00000200,
159 DISPATCH_SOCK_ADAPTIVE_RTIMO
= 0x00000400,
160 DISPATCH_SOCK_CONNECTED
= 0x00000800,
161 DISPATCH_SOCK_DISCONNECTED
= 0x00001000,
162 DISPATCH_SOCK_CONNINFO_UPDATED
= 0x00002000,
166 * @enum dispatch_source_vfs_flags_t
168 * @constant DISPATCH_VFS_NOTRESP
171 * @constant DISPATCH_VFS_NEEDAUTH
174 * @constant DISPATCH_VFS_LOWDISK
175 * We're low on space.
177 * @constant DISPATCH_VFS_MOUNT
178 * New filesystem arrived.
180 * @constant DISPATCH_VFS_UNMOUNT
181 * Filesystem has left.
183 * @constant DISPATCH_VFS_DEAD
184 * Filesystem is dead, needs force unmount.
186 * @constant DISPATCH_VFS_ASSIST
187 * Filesystem needs assistance from external program.
189 * @constant DISPATCH_VFS_NOTRESPLOCK
192 * @constant DISPATCH_VFS_UPDATE
193 * Filesystem information has changed.
195 * @constant DISPATCH_VFS_VERYLOWDISK
196 * File system has *very* little disk space left.
199 DISPATCH_VFS_NOTRESP
= 0x0001,
200 DISPATCH_VFS_NEEDAUTH
= 0x0002,
201 DISPATCH_VFS_LOWDISK
= 0x0004,
202 DISPATCH_VFS_MOUNT
= 0x0008,
203 DISPATCH_VFS_UNMOUNT
= 0x0010,
204 DISPATCH_VFS_DEAD
= 0x0020,
205 DISPATCH_VFS_ASSIST
= 0x0040,
206 DISPATCH_VFS_NOTRESPLOCK
= 0x0080,
207 DISPATCH_VFS_UPDATE
= 0x0100,
208 DISPATCH_VFS_VERYLOWDISK
= 0x0200,
212 * @enum dispatch_source_timer_flags_t
214 * @constant DISPATCH_TIMER_BACKGROUND
215 * Specifies that the timer is used to trigger low priority maintenance-level
216 * activity and that the system may apply larger minimum leeway values to the
217 * timer in order to align it with other system activity.
219 * @constant DISPATCH_INTERVAL_UI_ANIMATION
220 * Specifies that the interval source is used for UI animation. The unit for
221 * the interval value of such sources is frames (1/60th of a second) and the
222 * leeway is fixed at one frame.
225 DISPATCH_TIMER_BACKGROUND
= 0x2,
226 DISPATCH_INTERVAL_UI_ANIMATION
= 0x20,
230 * @enum dispatch_source_mach_send_flags_t
232 * @constant DISPATCH_MACH_SEND_POSSIBLE
233 * The mach port corresponding to the given send right has space available
234 * for messages. Delivered only once a mach_msg() to that send right with
235 * options MACH_SEND_MSG|MACH_SEND_TIMEOUT|MACH_SEND_NOTIFY has returned
236 * MACH_SEND_TIMED_OUT (and not again until the next such mach_msg() timeout).
237 * NOTE: The source must have registered the send right for monitoring with the
238 * system for such a mach_msg() to arm the send-possible notifcation, so
239 * the initial send attempt must occur from a source registration handler.
242 DISPATCH_MACH_SEND_POSSIBLE
= 0x8,
246 * @enum dispatch_source_proc_flags_t
248 * @constant DISPATCH_PROC_REAP
249 * The process has been reaped by the parent process via wait*().
250 * This flag is deprecated and will be removed in a future release.
253 DISPATCH_PROC_REAP
__OSX_AVAILABLE_BUT_DEPRECATED(
254 __MAC_10_6
, __MAC_10_9
, __IPHONE_4_0
, __IPHONE_7_0
) = 0x10000000,
258 * @enum dispatch_source_vm_flags_t
260 * @constant DISPATCH_VM_PRESSURE
261 * The VM has experienced memory pressure.
265 DISPATCH_VM_PRESSURE
= 0x80000000,
269 * @enum dispatch_source_memorystatus_flags_t
271 * @constant DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL
272 * The system's memory pressure state has returned to normal.
273 * @constant DISPATCH_MEMORYSTATUS_PRESSURE_WARN
274 * The system's memory pressure state has changed to warning.
275 * @constant DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL
276 * The system's memory pressure state has changed to critical.
280 DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL
= 0x01,
281 DISPATCH_MEMORYSTATUS_PRESSURE_WARN
= 0x02,
282 #if !TARGET_OS_EMBEDDED
283 DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL
= 0x04,
287 #if TARGET_IPHONE_SIMULATOR // rdar://problem/9219483
288 #define DISPATCH_VM_PRESSURE DISPATCH_VNODE_ATTRIB
294 * @typedef dispatch_timer_aggregate_t
297 * Dispatch timer aggregates are sets of related timers.
299 DISPATCH_DECL(dispatch_timer_aggregate
);
302 * @function dispatch_timer_aggregate_create
305 * Creates a new dispatch timer aggregate.
308 * A dispatch timer aggregate is a set of related timers whose overall timing
309 * parameters can be queried.
311 * Timers are added to an aggregate when a timer source is created with type
312 * DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE.
315 * The newly created dispatch timer aggregate.
317 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
318 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
320 dispatch_timer_aggregate_t
321 dispatch_timer_aggregate_create(void);
324 * @function dispatch_timer_aggregate_get_delay
327 * Retrieves the delay until a timer in the given aggregate will next fire.
330 * The dispatch timer aggregate to query.
333 * Optional pointer to a variable filled with the leeway (in ns) that will be
334 * applied to the return value. May be NULL.
337 * Delay in ns from now.
339 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
340 DISPATCH_EXPORT DISPATCH_NOTHROW
342 dispatch_timer_aggregate_get_delay(dispatch_timer_aggregate_t aggregate
,
343 uint64_t *leeway_ptr
);
347 * @typedef dispatch_mig_callback_t
350 * The signature of a function that handles Mach message delivery and response.
352 typedef boolean_t (*dispatch_mig_callback_t
)(mach_msg_header_t
*message
,
353 mach_msg_header_t
*reply
);
355 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
356 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
358 dispatch_mig_server(dispatch_source_t ds
, size_t maxmsgsz
,
359 dispatch_mig_callback_t callback
);
362 * @function dispatch_mach_msg_get_context
365 * Extract the context pointer from a mach message trailer.
367 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
368 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
371 dispatch_mach_msg_get_context(mach_msg_header_t
*msg
);