]> git.saurik.com Git - apple/libdispatch.git/blob - private/source_private.h
libdispatch-339.1.9.tar.gz
[apple/libdispatch.git] / private / source_private.h
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 /*
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.
25 */
26
27 #ifndef __DISPATCH_SOURCE_PRIVATE__
28 #define __DISPATCH_SOURCE_PRIVATE__
29
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/private.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
33 #endif
34
35 /*!
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.
40 */
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);
45
46 /*!
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.
51 *
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).
55 *
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.
59 *
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
62 * fixed at one frame.
63 *
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.
66 */
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);
70
71 /*!
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).
76 */
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;
80
81 /*!
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.
85 */
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;
89
90 /*!
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.
95 */
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;
100
101 /*!
102 * @const DISPATCH_SOURCE_TYPE_SOCK
103 * @discussion A dispatch source that monitors events on socket state changes.
104 */
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;
108
109 /*!
110 * @enum dispatch_source_sock_flags_t
111 *
112 * @constant DISPATCH_SOCK_CONNRESET
113 * Received RST
114 *
115 * @constant DISPATCH_SOCK_READCLOSED
116 * Read side is shutdown
117 *
118 * @constant DISPATCH_SOCK_WRITECLOSED
119 * Write side is shutdown
120 *
121 * @constant DISPATCH_SOCK_TIMEOUT
122 * Timeout: rexmt, keep-alive or persist
123 *
124 * @constant DISPATCH_SOCK_NOSRCADDR
125 * Source address not available
126 *
127 * @constant DISPATCH_SOCK_IFDENIED
128 * Interface denied connection
129 *
130 * @constant DISPATCH_SOCK_SUSPEND
131 * Output queue suspended
132 *
133 * @constant DISPATCH_SOCK_RESUME
134 * Output queue resumed
135 *
136 * @constant DISPATCH_SOCK_KEEPALIVE
137 * TCP Keepalive received
138 *
139 * @constant DISPATCH_SOCK_CONNECTED
140 * Socket is connected
141 *
142 * @constant DISPATCH_SOCK_DISCONNECTED
143 * Socket is disconnected
144 *
145 * @constant DISPATCH_SOCK_CONNINFO_UPDATED
146 * Connection info was updated
147 */
148 enum {
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,
163 };
164
165 /*!
166 * @enum dispatch_source_vfs_flags_t
167 *
168 * @constant DISPATCH_VFS_NOTRESP
169 * Server down.
170 *
171 * @constant DISPATCH_VFS_NEEDAUTH
172 * Server bad auth.
173 *
174 * @constant DISPATCH_VFS_LOWDISK
175 * We're low on space.
176 *
177 * @constant DISPATCH_VFS_MOUNT
178 * New filesystem arrived.
179 *
180 * @constant DISPATCH_VFS_UNMOUNT
181 * Filesystem has left.
182 *
183 * @constant DISPATCH_VFS_DEAD
184 * Filesystem is dead, needs force unmount.
185 *
186 * @constant DISPATCH_VFS_ASSIST
187 * Filesystem needs assistance from external program.
188 *
189 * @constant DISPATCH_VFS_NOTRESPLOCK
190 * Server lockd down.
191 *
192 * @constant DISPATCH_VFS_UPDATE
193 * Filesystem information has changed.
194 *
195 * @constant DISPATCH_VFS_VERYLOWDISK
196 * File system has *very* little disk space left.
197 */
198 enum {
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,
209 };
210
211 /*!
212 * @enum dispatch_source_timer_flags_t
213 *
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.
218 *
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.
223 */
224 enum {
225 DISPATCH_TIMER_BACKGROUND = 0x2,
226 DISPATCH_INTERVAL_UI_ANIMATION = 0x20,
227 };
228
229 /*!
230 * @enum dispatch_source_mach_send_flags_t
231 *
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.
240 */
241 enum {
242 DISPATCH_MACH_SEND_POSSIBLE = 0x8,
243 };
244
245 /*!
246 * @enum dispatch_source_proc_flags_t
247 *
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.
251 */
252 enum {
253 DISPATCH_PROC_REAP __OSX_AVAILABLE_BUT_DEPRECATED(
254 __MAC_10_6, __MAC_10_9, __IPHONE_4_0, __IPHONE_7_0) = 0x10000000,
255 };
256
257 /*!
258 * @enum dispatch_source_vm_flags_t
259 *
260 * @constant DISPATCH_VM_PRESSURE
261 * The VM has experienced memory pressure.
262 */
263
264 enum {
265 DISPATCH_VM_PRESSURE = 0x80000000,
266 };
267
268 /*!
269 * @enum dispatch_source_memorystatus_flags_t
270 *
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.
277 */
278
279 enum {
280 DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL = 0x01,
281 DISPATCH_MEMORYSTATUS_PRESSURE_WARN = 0x02,
282 #if !TARGET_OS_EMBEDDED
283 DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL = 0x04,
284 #endif
285 };
286
287 #if TARGET_IPHONE_SIMULATOR // rdar://problem/9219483
288 #define DISPATCH_VM_PRESSURE DISPATCH_VNODE_ATTRIB
289 #endif
290
291 __BEGIN_DECLS
292
293 /*!
294 * @typedef dispatch_timer_aggregate_t
295 *
296 * @abstract
297 * Dispatch timer aggregates are sets of related timers.
298 */
299 DISPATCH_DECL(dispatch_timer_aggregate);
300
301 /*!
302 * @function dispatch_timer_aggregate_create
303 *
304 * @abstract
305 * Creates a new dispatch timer aggregate.
306 *
307 * @discussion
308 * A dispatch timer aggregate is a set of related timers whose overall timing
309 * parameters can be queried.
310 *
311 * Timers are added to an aggregate when a timer source is created with type
312 * DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE.
313 *
314 * @result
315 * The newly created dispatch timer aggregate.
316 */
317 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
318 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
319 DISPATCH_NOTHROW
320 dispatch_timer_aggregate_t
321 dispatch_timer_aggregate_create(void);
322
323 /*!
324 * @function dispatch_timer_aggregate_get_delay
325 *
326 * @abstract
327 * Retrieves the delay until a timer in the given aggregate will next fire.
328 *
329 * @param aggregate
330 * The dispatch timer aggregate to query.
331 *
332 * @param leeway_ptr
333 * Optional pointer to a variable filled with the leeway (in ns) that will be
334 * applied to the return value. May be NULL.
335 *
336 * @result
337 * Delay in ns from now.
338 */
339 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
340 DISPATCH_EXPORT DISPATCH_NOTHROW
341 uint64_t
342 dispatch_timer_aggregate_get_delay(dispatch_timer_aggregate_t aggregate,
343 uint64_t *leeway_ptr);
344
345 #if TARGET_OS_MAC
346 /*!
347 * @typedef dispatch_mig_callback_t
348 *
349 * @abstract
350 * The signature of a function that handles Mach message delivery and response.
351 */
352 typedef boolean_t (*dispatch_mig_callback_t)(mach_msg_header_t *message,
353 mach_msg_header_t *reply);
354
355 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
356 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
357 mach_msg_return_t
358 dispatch_mig_server(dispatch_source_t ds, size_t maxmsgsz,
359 dispatch_mig_callback_t callback);
360
361 /*!
362 * @function dispatch_mach_msg_get_context
363 *
364 * @abstract
365 * Extract the context pointer from a mach message trailer.
366 */
367 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
368 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
369 DISPATCH_NOTHROW
370 void *
371 dispatch_mach_msg_get_context(mach_msg_header_t *msg);
372 #endif
373
374 __END_DECLS
375
376 #endif