]> git.saurik.com Git - apple/libdispatch.git/blob - private/source_private.h
libdispatch-703.50.37.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 DISPATCH_ASSUME_NONNULL_BEGIN
36
37 __BEGIN_DECLS
38
39 /*!
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.
44 */
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);
49
50 /*!
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.
55 *
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).
59 *
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.
63 *
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
66 * fixed at one frame.
67 *
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.
70 */
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);
74
75 /*!
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).
80 */
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;
84
85 /*!
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.
90 */
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;
96
97 /*!
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.
102 */
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;
111
112 /*!
113 * @const DISPATCH_SOURCE_TYPE_SOCK
114 * @discussion A dispatch source that monitors events on socket state changes.
115 */
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;
119
120 __END_DECLS
121
122 /*!
123 * @enum dispatch_source_sock_flags_t
124 *
125 * @constant DISPATCH_SOCK_CONNRESET
126 * Received RST
127 *
128 * @constant DISPATCH_SOCK_READCLOSED
129 * Read side is shutdown
130 *
131 * @constant DISPATCH_SOCK_WRITECLOSED
132 * Write side is shutdown
133 *
134 * @constant DISPATCH_SOCK_TIMEOUT
135 * Timeout: rexmt, keep-alive or persist
136 *
137 * @constant DISPATCH_SOCK_NOSRCADDR
138 * Source address not available
139 *
140 * @constant DISPATCH_SOCK_IFDENIED
141 * Interface denied connection
142 *
143 * @constant DISPATCH_SOCK_SUSPEND
144 * Output queue suspended
145 *
146 * @constant DISPATCH_SOCK_RESUME
147 * Output queue resumed
148 *
149 * @constant DISPATCH_SOCK_KEEPALIVE
150 * TCP Keepalive received
151 *
152 * @constant DISPATCH_SOCK_CONNECTED
153 * Socket is connected
154 *
155 * @constant DISPATCH_SOCK_DISCONNECTED
156 * Socket is disconnected
157 *
158 * @constant DISPATCH_SOCK_CONNINFO_UPDATED
159 * Connection info was updated
160 *
161 * @constant DISPATCH_SOCK_NOTIFY_ACK
162 * Notify acknowledgement
163 */
164 enum {
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,
180 };
181
182 /*!
183 * @enum dispatch_source_vfs_flags_t
184 *
185 * @constant DISPATCH_VFS_NOTRESP
186 * Server down.
187 *
188 * @constant DISPATCH_VFS_NEEDAUTH
189 * Server bad auth.
190 *
191 * @constant DISPATCH_VFS_LOWDISK
192 * We're low on space.
193 *
194 * @constant DISPATCH_VFS_MOUNT
195 * New filesystem arrived.
196 *
197 * @constant DISPATCH_VFS_UNMOUNT
198 * Filesystem has left.
199 *
200 * @constant DISPATCH_VFS_DEAD
201 * Filesystem is dead, needs force unmount.
202 *
203 * @constant DISPATCH_VFS_ASSIST
204 * Filesystem needs assistance from external program.
205 *
206 * @constant DISPATCH_VFS_NOTRESPLOCK
207 * Server lockd down.
208 *
209 * @constant DISPATCH_VFS_UPDATE
210 * Filesystem information has changed.
211 *
212 * @constant DISPATCH_VFS_VERYLOWDISK
213 * File system has *very* little disk space left.
214 *
215 * @constant DISPATCH_VFS_QUOTA
216 * We hit a user quota (quotactl) for this filesystem.
217 *
218 * @constant DISPATCH_VFS_NEARLOWDISK
219 * Filesystem is nearly full (below NEARLOWDISK level).
220 *
221 * @constant DISPATCH_VFS_DESIREDDISK
222 * Filesystem has exceeded the DESIREDDISK level
223 */
224 enum {
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,
238 };
239
240 /*!
241 * @enum dispatch_source_timer_flags_t
242 *
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.
247 *
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.
252 */
253 enum {
254 DISPATCH_TIMER_BACKGROUND = 0x2,
255 DISPATCH_INTERVAL_UI_ANIMATION = 0x20,
256 };
257
258 /*!
259 * @enum dispatch_source_mach_send_flags_t
260 *
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.
269 */
270 enum {
271 DISPATCH_MACH_SEND_POSSIBLE = 0x8,
272 };
273
274 /*!
275 * @enum dispatch_source_proc_flags_t
276 *
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.
280 */
281 enum {
282 DISPATCH_PROC_REAP __OSX_AVAILABLE_BUT_DEPRECATED(
283 __MAC_10_6, __MAC_10_9, __IPHONE_4_0, __IPHONE_7_0) = 0x10000000,
284 };
285
286 /*!
287 * @enum dispatch_source_vm_flags_t
288 *
289 * @constant DISPATCH_VM_PRESSURE
290 * The VM has experienced memory pressure.
291 */
292
293 enum {
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,
297 };
298
299 /*!
300 * @typedef dispatch_source_memorypressure_flags_t
301 * Type of dispatch_source_memorypressure flags
302 *
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.
306 */
307 enum {
308 DISPATCH_MEMORYPRESSURE_LOW_SWAP
309 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0) = 0x08,
310 };
311
312 /*!
313 * @enum dispatch_source_memorystatus_flags_t
314 * @warning Deprecated, see DISPATCH_MEMORYPRESSURE_*
315 */
316 enum {
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")
322 = 0x01,
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")
328 = 0x02,
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")
334 = 0x04,
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")
340 = 0x08,
341 };
342
343 /*!
344 * @typedef dispatch_source_memorypressure_flags_t
345 * Type of dispatch_source_memorypressure flags
346 *
347 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
348 * The memory of the process has crossed 80% of its high watermark limit.
349 *
350 * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
351 * The memory of the process has reached 100% of its high watermark limit.
352 */
353 enum {
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,
357
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,
361 };
362
363
364 __BEGIN_DECLS
365
366 /*!
367 * @function dispatch_source_cancel_and_wait
368 *
369 * @abstract
370 * Synchronously cancel the dispatch source, preventing any further invocation
371 * of its event handler block.
372 *
373 * @discussion
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.
377 *
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.
382 *
383 * If the specified dispatch source is inactive, it will be activated as a side
384 * effect of calling this function.
385 *
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.
389 *
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
393 * cancel handler.
394 *
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.
397 *
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.
402 *
403 * This function must not be called on sources suspended with an explicit
404 * call to dispatch_suspend(), or being concurrently activated on another
405 * thread.
406 *
407 * @param source
408 * The dispatch source to be canceled.
409 * The result of passing NULL in this parameter is undefined.
410 */
411 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.10)
412 __TVOS_AVAILABLE(10.10) __WATCHOS_AVAILABLE(3.0)
413 DISPATCH_EXPORT DISPATCH_NOTHROW
414 void
415 dispatch_source_cancel_and_wait(dispatch_source_t source);
416
417 /*!
418 * @typedef dispatch_timer_aggregate_t
419 *
420 * @abstract
421 * Dispatch timer aggregates are sets of related timers.
422 */
423 DISPATCH_DECL(dispatch_timer_aggregate);
424
425 /*!
426 * @function dispatch_timer_aggregate_create
427 *
428 * @abstract
429 * Creates a new dispatch timer aggregate.
430 *
431 * @discussion
432 * A dispatch timer aggregate is a set of related timers whose overall timing
433 * parameters can be queried.
434 *
435 * Timers are added to an aggregate when a timer source is created with type
436 * DISPATCH_SOURCE_TYPE_TIMER_WITH_AGGREGATE.
437 *
438 * @result
439 * The newly created dispatch timer aggregate.
440 */
441 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
442 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
443 DISPATCH_NOTHROW
444 dispatch_timer_aggregate_t
445 dispatch_timer_aggregate_create(void);
446
447 /*!
448 * @function dispatch_timer_aggregate_get_delay
449 *
450 * @abstract
451 * Retrieves the delay until a timer in the given aggregate will next fire.
452 *
453 * @param aggregate
454 * The dispatch timer aggregate to query.
455 *
456 * @param leeway_ptr
457 * Optional pointer to a variable filled with the leeway (in ns) that will be
458 * applied to the return value. May be NULL.
459 *
460 * @result
461 * Delay in ns from now.
462 */
463 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
464 DISPATCH_EXPORT DISPATCH_NOTHROW
465 uint64_t
466 dispatch_timer_aggregate_get_delay(dispatch_timer_aggregate_t aggregate,
467 uint64_t *_Nullable leeway_ptr);
468
469 #if __has_include(<mach/mach.h>)
470 /*!
471 * @typedef dispatch_mig_callback_t
472 *
473 * @abstract
474 * The signature of a function that handles Mach message delivery and response.
475 */
476 typedef boolean_t (*dispatch_mig_callback_t)(mach_msg_header_t *message,
477 mach_msg_header_t *reply);
478
479 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0) DISPATCH_LINUX_UNAVAILABLE()
480 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
481 mach_msg_return_t
482 dispatch_mig_server(dispatch_source_t ds, size_t maxmsgsz,
483 dispatch_mig_callback_t callback);
484
485 /*!
486 * @function dispatch_mach_msg_get_context
487 *
488 * @abstract
489 * Extract the context pointer from a mach message trailer.
490 */
491 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0) DISPATCH_LINUX_UNAVAILABLE()
492 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
493 DISPATCH_NOTHROW
494 void *_Nullable
495 dispatch_mach_msg_get_context(mach_msg_header_t *msg);
496 #endif
497
498 __END_DECLS
499
500 DISPATCH_ASSUME_NONNULL_END
501
502 #endif