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@
21 #ifndef __DISPATCH_SOURCE__
22 #define __DISPATCH_SOURCE__
24 #ifndef __DISPATCH_INDIRECT__
25 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
26 #include <dispatch/base.h> // for HeaderDoc
30 #include <mach/port.h>
31 #include <mach/message.h>
35 #include <sys/signal.h>
38 DISPATCH_ASSUME_NONNULL_BEGIN
42 * The dispatch framework provides a suite of interfaces for monitoring low-
43 * level system objects (file descriptors, Mach ports, signals, VFS nodes, etc.)
44 * for activity and automatically submitting event handler blocks to dispatch
45 * queues when such activity occurs.
47 * This suite of interfaces is known as the Dispatch Source API.
51 * @typedef dispatch_source_t
54 * Dispatch sources are used to automatically submit event handler blocks to
55 * dispatch queues in response to external events.
57 DISPATCH_SOURCE_DECL(dispatch_source
);
62 * @typedef dispatch_source_type_t
65 * Constants of this type represent the class of low-level system object that
66 * is being monitored by the dispatch source. Constants of this type are
67 * passed as a parameter to dispatch_source_create() and determine how the
68 * handle argument is interpreted (i.e. as a file descriptor, mach port,
69 * signal number, process identifier, etc.), and how the mask argument is
72 typedef const struct dispatch_source_type_s
*dispatch_source_type_t
;
75 * @const DISPATCH_SOURCE_TYPE_DATA_ADD
76 * @discussion A dispatch source that coalesces data obtained via calls to
77 * dispatch_source_merge_data(). An ADD is used to coalesce the data.
78 * The handle is unused (pass zero for now).
79 * The mask is unused (pass zero for now).
81 #define DISPATCH_SOURCE_TYPE_DATA_ADD (&_dispatch_source_type_data_add)
82 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
83 DISPATCH_SOURCE_TYPE_DECL(data_add
);
86 * @const DISPATCH_SOURCE_TYPE_DATA_OR
87 * @discussion A dispatch source that coalesces data obtained via calls to
88 * dispatch_source_merge_data(). A bitwise OR is used to coalesce the data.
89 * The handle is unused (pass zero for now).
90 * The mask is unused (pass zero for now).
92 #define DISPATCH_SOURCE_TYPE_DATA_OR (&_dispatch_source_type_data_or)
93 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
94 DISPATCH_SOURCE_TYPE_DECL(data_or
);
97 * @const DISPATCH_SOURCE_TYPE_MACH_SEND
98 * @discussion A dispatch source that monitors a Mach port for dead name
99 * notifications (send right no longer has any corresponding receive right).
100 * The handle is a Mach port with a send or send-once right (mach_port_t).
101 * The mask is a mask of desired events from dispatch_source_mach_send_flags_t.
103 #define DISPATCH_SOURCE_TYPE_MACH_SEND (&_dispatch_source_type_mach_send)
104 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
105 DISPATCH_SOURCE_TYPE_DECL(mach_send
);
108 * @const DISPATCH_SOURCE_TYPE_MACH_RECV
109 * @discussion A dispatch source that monitors a Mach port for pending messages.
110 * The handle is a Mach port with a receive right (mach_port_t).
111 * The mask is unused (pass zero for now).
113 #define DISPATCH_SOURCE_TYPE_MACH_RECV (&_dispatch_source_type_mach_recv)
114 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
115 DISPATCH_SOURCE_TYPE_DECL(mach_recv
);
118 * @const DISPATCH_SOURCE_TYPE_MEMORYPRESSURE
119 * @discussion A dispatch source that monitors the system for changes in
120 * memory pressure condition.
121 * The handle is unused (pass zero for now).
122 * The mask is a mask of desired events from
123 * dispatch_source_memorypressure_flags_t.
125 #define DISPATCH_SOURCE_TYPE_MEMORYPRESSURE \
126 (&_dispatch_source_type_memorypressure)
127 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_8_0
) DISPATCH_LINUX_UNAVAILABLE()
128 DISPATCH_SOURCE_TYPE_DECL(memorypressure
);
131 * @const DISPATCH_SOURCE_TYPE_PROC
132 * @discussion A dispatch source that monitors an external process for events
133 * defined by dispatch_source_proc_flags_t.
134 * The handle is a process identifier (pid_t).
135 * The mask is a mask of desired events from dispatch_source_proc_flags_t.
137 #define DISPATCH_SOURCE_TYPE_PROC (&_dispatch_source_type_proc)
138 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
139 DISPATCH_SOURCE_TYPE_DECL(proc
);
142 * @const DISPATCH_SOURCE_TYPE_READ
143 * @discussion A dispatch source that monitors a file descriptor for pending
144 * bytes available to be read.
145 * The handle is a file descriptor (int).
146 * The mask is unused (pass zero for now).
148 #define DISPATCH_SOURCE_TYPE_READ (&_dispatch_source_type_read)
149 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
150 DISPATCH_SOURCE_TYPE_DECL(read
);
153 * @const DISPATCH_SOURCE_TYPE_SIGNAL
154 * @discussion A dispatch source that monitors the current process for signals.
155 * The handle is a signal number (int).
156 * The mask is unused (pass zero for now).
158 #define DISPATCH_SOURCE_TYPE_SIGNAL (&_dispatch_source_type_signal)
159 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
160 DISPATCH_SOURCE_TYPE_DECL(signal
);
163 * @const DISPATCH_SOURCE_TYPE_TIMER
164 * @discussion A dispatch source that submits the event handler block based
166 * The handle is unused (pass zero for now).
167 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
169 #define DISPATCH_SOURCE_TYPE_TIMER (&_dispatch_source_type_timer)
170 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
171 DISPATCH_SOURCE_TYPE_DECL(timer
);
174 * @const DISPATCH_SOURCE_TYPE_VNODE
175 * @discussion A dispatch source that monitors a file descriptor for events
176 * defined by dispatch_source_vnode_flags_t.
177 * The handle is a file descriptor (int).
178 * The mask is a mask of desired events from dispatch_source_vnode_flags_t.
180 #define DISPATCH_SOURCE_TYPE_VNODE (&_dispatch_source_type_vnode)
181 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
) DISPATCH_LINUX_UNAVAILABLE()
182 DISPATCH_SOURCE_TYPE_DECL(vnode
);
185 * @const DISPATCH_SOURCE_TYPE_WRITE
186 * @discussion A dispatch source that monitors a file descriptor for available
187 * buffer space to write bytes.
188 * The handle is a file descriptor (int).
189 * The mask is unused (pass zero for now).
191 #define DISPATCH_SOURCE_TYPE_WRITE (&_dispatch_source_type_write)
192 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
193 DISPATCH_SOURCE_TYPE_DECL(write
);
196 * @typedef dispatch_source_mach_send_flags_t
197 * Type of dispatch_source_mach_send flags
199 * @constant DISPATCH_MACH_SEND_DEAD
200 * The receive right corresponding to the given send right was destroyed.
202 #define DISPATCH_MACH_SEND_DEAD 0x1
204 typedef unsigned long dispatch_source_mach_send_flags_t
;
207 * @typedef dispatch_source_memorypressure_flags_t
208 * Type of dispatch_source_memorypressure flags
210 * @constant DISPATCH_MEMORYPRESSURE_NORMAL
211 * The system memory pressure condition has returned to normal.
213 * @constant DISPATCH_MEMORYPRESSURE_WARN
214 * The system memory pressure condition has changed to warning.
216 * @constant DISPATCH_MEMORYPRESSURE_CRITICAL
217 * The system memory pressure condition has changed to critical.
220 * Elevated memory pressure is a system-wide condition that applications
221 * registered for this source should react to by changing their future memory
222 * use behavior, e.g. by reducing cache sizes of newly initiated operations
223 * until memory pressure returns back to normal.
224 * NOTE: applications should NOT traverse and discard existing caches for past
225 * operations when the system memory pressure enters an elevated state, as that
226 * is likely to trigger VM operations that will further aggravate system memory
230 #define DISPATCH_MEMORYPRESSURE_NORMAL 0x01
231 #define DISPATCH_MEMORYPRESSURE_WARN 0x02
232 #define DISPATCH_MEMORYPRESSURE_CRITICAL 0x04
234 typedef unsigned long dispatch_source_memorypressure_flags_t
;
237 * @typedef dispatch_source_proc_flags_t
238 * Type of dispatch_source_proc flags
240 * @constant DISPATCH_PROC_EXIT
241 * The process has exited (perhaps cleanly, perhaps not).
243 * @constant DISPATCH_PROC_FORK
244 * The process has created one or more child processes.
246 * @constant DISPATCH_PROC_EXEC
247 * The process has become another executable image via
248 * exec*() or posix_spawn*().
250 * @constant DISPATCH_PROC_SIGNAL
251 * A Unix signal was delivered to the process.
253 #define DISPATCH_PROC_EXIT 0x80000000
254 #define DISPATCH_PROC_FORK 0x40000000
255 #define DISPATCH_PROC_EXEC 0x20000000
256 #define DISPATCH_PROC_SIGNAL 0x08000000
258 typedef unsigned long dispatch_source_proc_flags_t
;
261 * @typedef dispatch_source_vnode_flags_t
262 * Type of dispatch_source_vnode flags
264 * @constant DISPATCH_VNODE_DELETE
265 * The filesystem object was deleted from the namespace.
267 * @constant DISPATCH_VNODE_WRITE
268 * The filesystem object data changed.
270 * @constant DISPATCH_VNODE_EXTEND
271 * The filesystem object changed in size.
273 * @constant DISPATCH_VNODE_ATTRIB
274 * The filesystem object metadata changed.
276 * @constant DISPATCH_VNODE_LINK
277 * The filesystem object link count changed.
279 * @constant DISPATCH_VNODE_RENAME
280 * The filesystem object was renamed in the namespace.
282 * @constant DISPATCH_VNODE_REVOKE
283 * The filesystem object was revoked.
285 * @constant DISPATCH_VNODE_FUNLOCK
286 * The filesystem object was unlocked.
289 #define DISPATCH_VNODE_DELETE 0x1
290 #define DISPATCH_VNODE_WRITE 0x2
291 #define DISPATCH_VNODE_EXTEND 0x4
292 #define DISPATCH_VNODE_ATTRIB 0x8
293 #define DISPATCH_VNODE_LINK 0x10
294 #define DISPATCH_VNODE_RENAME 0x20
295 #define DISPATCH_VNODE_REVOKE 0x40
296 #define DISPATCH_VNODE_FUNLOCK 0x100
298 typedef unsigned long dispatch_source_vnode_flags_t
;
301 * @typedef dispatch_source_timer_flags_t
302 * Type of dispatch_source_timer flags
304 * @constant DISPATCH_TIMER_STRICT
305 * Specifies that the system should make a best effort to strictly observe the
306 * leeway value specified for the timer via dispatch_source_set_timer(), even
307 * if that value is smaller than the default leeway value that would be applied
308 * to the timer otherwise. A minimal amount of leeway will be applied to the
309 * timer even if this flag is specified.
311 * CAUTION: Use of this flag may override power-saving techniques employed by
312 * the system and cause higher power consumption, so it must be used with care
313 * and only when absolutely necessary.
316 #define DISPATCH_TIMER_STRICT 0x1
318 typedef unsigned long dispatch_source_timer_flags_t
;
321 * @function dispatch_source_create
324 * Creates a new dispatch source to monitor low-level system objects and auto-
325 * matically submit a handler block to a dispatch queue in response to events.
328 * Dispatch sources are not reentrant. Any events received while the dispatch
329 * source is suspended or while the event handler block is currently executing
330 * will be coalesced and delivered after the dispatch source is resumed or the
331 * event handler block has returned.
333 * Dispatch sources are created in an inactive state. After creating the
334 * source and setting any desired attributes (i.e. the handler, context, etc.),
335 * a call must be made to dispatch_activate() in order to begin event delivery.
337 * Calling dispatch_set_target_queue() on a source once it has been activated
338 * is not allowed (see dispatch_activate() and dispatch_set_target_queue()).
340 * For backward compatibility reasons, dispatch_resume() on an inactive,
341 * and not otherwise suspended source has the same effect as calling
342 * dispatch_activate(). For new code, using dispatch_activate() is preferred.
345 * Declares the type of the dispatch source. Must be one of the defined
346 * dispatch_source_type_t constants.
349 * The underlying system handle to monitor. The interpretation of this argument
350 * is determined by the constant provided in the type parameter.
353 * A mask of flags specifying which events are desired. The interpretation of
354 * this argument is determined by the constant provided in the type parameter.
357 * The dispatch queue to which the event handler block will be submitted.
358 * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, the source will submit the event
359 * handler block to the default priority global queue.
362 * The newly created dispatch source. Or NULL if invalid arguments are passed.
364 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
365 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
368 dispatch_source_create(dispatch_source_type_t type
,
371 dispatch_queue_t _Nullable queue
);
374 * @function dispatch_source_set_event_handler
377 * Sets the event handler block for the given dispatch source.
380 * The dispatch source to modify.
381 * The result of passing NULL in this parameter is undefined.
384 * The event handler block to submit to the source's target queue.
387 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
388 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
390 dispatch_source_set_event_handler(dispatch_source_t source
,
391 dispatch_block_t _Nullable handler
);
392 #endif /* __BLOCKS__ */
395 * @function dispatch_source_set_event_handler_f
398 * Sets the event handler function for the given dispatch source.
401 * The dispatch source to modify.
402 * The result of passing NULL in this parameter is undefined.
405 * The event handler function to submit to the source's target queue.
406 * The context parameter passed to the event handler function is the context of
407 * the dispatch source current at the time the event handler was set.
409 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
410 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
412 dispatch_source_set_event_handler_f(dispatch_source_t source
,
413 dispatch_function_t _Nullable handler
);
416 * @function dispatch_source_set_cancel_handler
419 * Sets the cancellation handler block for the given dispatch source.
422 * The cancellation handler (if specified) will be submitted to the source's
423 * target queue in response to a call to dispatch_source_cancel() once the
424 * system has released all references to the source's underlying handle and
425 * the source's event handler block has returned.
428 * A cancellation handler is required for file descriptor and mach port based
429 * sources in order to safely close the descriptor or destroy the port. Closing
430 * the descriptor or port before the cancellation handler may result in a race
431 * condition. If a new descriptor is allocated with the same value as the
432 * recently closed descriptor while the source's event handler is still running,
433 * the event handler may read/write data to the wrong descriptor.
436 * The dispatch source to modify.
437 * The result of passing NULL in this parameter is undefined.
440 * The cancellation handler block to submit to the source's target queue.
443 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
444 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
446 dispatch_source_set_cancel_handler(dispatch_source_t source
,
447 dispatch_block_t _Nullable handler
);
448 #endif /* __BLOCKS__ */
451 * @function dispatch_source_set_cancel_handler_f
454 * Sets the cancellation handler function for the given dispatch source.
457 * See dispatch_source_set_cancel_handler() for more details.
460 * The dispatch source to modify.
461 * The result of passing NULL in this parameter is undefined.
464 * The cancellation handler function to submit to the source's target queue.
465 * The context parameter passed to the event handler function is the current
466 * context of the dispatch source at the time the handler call is made.
468 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
469 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
471 dispatch_source_set_cancel_handler_f(dispatch_source_t source
,
472 dispatch_function_t _Nullable handler
);
475 * @function dispatch_source_cancel
478 * Asynchronously cancel the dispatch source, preventing any further invocation
479 * of its event handler block.
482 * Cancellation prevents any further invocation of the event handler block for
483 * the specified dispatch source, but does not interrupt an event handler
484 * block that is already in progress.
486 * The cancellation handler is submitted to the source's target queue once the
487 * the source's event handler has finished, indicating it is now safe to close
488 * the source's handle (i.e. file descriptor or mach port).
490 * See dispatch_source_set_cancel_handler() for more information.
493 * The dispatch source to be canceled.
494 * The result of passing NULL in this parameter is undefined.
496 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
497 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
499 dispatch_source_cancel(dispatch_source_t source
);
502 * @function dispatch_source_testcancel
505 * Tests whether the given dispatch source has been canceled.
508 * The dispatch source to be tested.
509 * The result of passing NULL in this parameter is undefined.
512 * Non-zero if canceled and zero if not canceled.
514 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
515 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
518 dispatch_source_testcancel(dispatch_source_t source
);
521 * @function dispatch_source_get_handle
524 * Returns the underlying system handle associated with this dispatch source.
527 * The result of passing NULL in this parameter is undefined.
530 * The return value should be interpreted according to the type of the dispatch
531 * source, and may be one of the following handles:
533 * DISPATCH_SOURCE_TYPE_DATA_ADD: n/a
534 * DISPATCH_SOURCE_TYPE_DATA_OR: n/a
535 * DISPATCH_SOURCE_TYPE_MACH_SEND: mach port (mach_port_t)
536 * DISPATCH_SOURCE_TYPE_MACH_RECV: mach port (mach_port_t)
537 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE n/a
538 * DISPATCH_SOURCE_TYPE_PROC: process identifier (pid_t)
539 * DISPATCH_SOURCE_TYPE_READ: file descriptor (int)
540 * DISPATCH_SOURCE_TYPE_SIGNAL: signal number (int)
541 * DISPATCH_SOURCE_TYPE_TIMER: n/a
542 * DISPATCH_SOURCE_TYPE_VNODE: file descriptor (int)
543 * DISPATCH_SOURCE_TYPE_WRITE: file descriptor (int)
545 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
546 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
549 dispatch_source_get_handle(dispatch_source_t source
);
552 * @function dispatch_source_get_mask
555 * Returns the mask of events monitored by the dispatch source.
558 * The result of passing NULL in this parameter is undefined.
561 * The return value should be interpreted according to the type of the dispatch
562 * source, and may be one of the following flag sets:
564 * DISPATCH_SOURCE_TYPE_DATA_ADD: n/a
565 * DISPATCH_SOURCE_TYPE_DATA_OR: n/a
566 * DISPATCH_SOURCE_TYPE_MACH_SEND: dispatch_source_mach_send_flags_t
567 * DISPATCH_SOURCE_TYPE_MACH_RECV: n/a
568 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE dispatch_source_memorypressure_flags_t
569 * DISPATCH_SOURCE_TYPE_PROC: dispatch_source_proc_flags_t
570 * DISPATCH_SOURCE_TYPE_READ: n/a
571 * DISPATCH_SOURCE_TYPE_SIGNAL: n/a
572 * DISPATCH_SOURCE_TYPE_TIMER: dispatch_source_timer_flags_t
573 * DISPATCH_SOURCE_TYPE_VNODE: dispatch_source_vnode_flags_t
574 * DISPATCH_SOURCE_TYPE_WRITE: n/a
576 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
577 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
580 dispatch_source_get_mask(dispatch_source_t source
);
583 * @function dispatch_source_get_data
586 * Returns pending data for the dispatch source.
589 * This function is intended to be called from within the event handler block.
590 * The result of calling this function outside of the event handler callback is
594 * The result of passing NULL in this parameter is undefined.
597 * The return value should be interpreted according to the type of the dispatch
598 * source, and may be one of the following:
600 * DISPATCH_SOURCE_TYPE_DATA_ADD: application defined data
601 * DISPATCH_SOURCE_TYPE_DATA_OR: application defined data
602 * DISPATCH_SOURCE_TYPE_MACH_SEND: dispatch_source_mach_send_flags_t
603 * DISPATCH_SOURCE_TYPE_MACH_RECV: n/a
604 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE dispatch_source_memorypressure_flags_t
605 * DISPATCH_SOURCE_TYPE_PROC: dispatch_source_proc_flags_t
606 * DISPATCH_SOURCE_TYPE_READ: estimated bytes available to read
607 * DISPATCH_SOURCE_TYPE_SIGNAL: number of signals delivered since
608 * the last handler invocation
609 * DISPATCH_SOURCE_TYPE_TIMER: number of times the timer has fired
610 * since the last handler invocation
611 * DISPATCH_SOURCE_TYPE_VNODE: dispatch_source_vnode_flags_t
612 * DISPATCH_SOURCE_TYPE_WRITE: estimated buffer space available
614 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
615 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
618 dispatch_source_get_data(dispatch_source_t source
);
621 * @function dispatch_source_merge_data
624 * Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or
625 * DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its
629 * The result of passing NULL in this parameter is undefined.
632 * The value to coalesce with the pending data using a logical OR or an ADD
633 * as specified by the dispatch source type. A value of zero has no effect
634 * and will not result in the submission of the event handler block.
636 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
637 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
639 dispatch_source_merge_data(dispatch_source_t source
, unsigned long value
);
642 * @function dispatch_source_set_timer
645 * Sets a start time, interval, and leeway value for a timer source.
648 * Once this function returns, any pending source data accumulated for the
649 * previous timer values has been cleared; the next fire of the timer will
650 * occur at 'start', and every 'interval' nanoseconds thereafter until the
651 * timer source is canceled.
653 * Any fire of the timer may be delayed by the system in order to improve power
654 * consumption and system performance. The upper limit to the allowable delay
655 * may be configured with the 'leeway' argument, the lower limit is under the
656 * control of the system.
658 * For the initial timer fire at 'start', the upper limit to the allowable
659 * delay is set to 'leeway' nanoseconds. For the subsequent timer fires at
660 * 'start' + N * 'interval', the upper limit is MIN('leeway','interval'/2).
662 * The lower limit to the allowable delay may vary with process state such as
663 * visibility of application UI. If the specified timer source was created with
664 * a mask of DISPATCH_TIMER_STRICT, the system will make a best effort to
665 * strictly observe the provided 'leeway' value even if it is smaller than the
666 * current lower limit. Note that a minimal amount of delay is to be expected
667 * even if this flag is specified.
669 * The 'start' argument also determines which clock will be used for the timer:
670 * If 'start' is DISPATCH_TIME_NOW or was created with dispatch_time(3), the
671 * timer is based on mach_absolute_time(). If 'start' was created with
672 * dispatch_walltime(3), the timer is based on gettimeofday(3).
674 * Calling this function has no effect if the timer source has already been
678 * The start time of the timer. See dispatch_time() and dispatch_walltime()
679 * for more information.
682 * The nanosecond interval for the timer. Use DISPATCH_TIME_FOREVER for a
686 * The nanosecond leeway for the timer.
688 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
689 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
691 dispatch_source_set_timer(dispatch_source_t source
,
692 dispatch_time_t start
,
697 * @function dispatch_source_set_registration_handler
700 * Sets the registration handler block for the given dispatch source.
703 * The registration handler (if specified) will be submitted to the source's
704 * target queue once the corresponding kevent() has been registered with the
705 * system, following the initial dispatch_resume() of the source.
707 * If a source is already registered when the registration handler is set, the
708 * registration handler will be invoked immediately.
711 * The dispatch source to modify.
712 * The result of passing NULL in this parameter is undefined.
715 * The registration handler block to submit to the source's target queue.
718 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
719 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
721 dispatch_source_set_registration_handler(dispatch_source_t source
,
722 dispatch_block_t _Nullable handler
);
723 #endif /* __BLOCKS__ */
726 * @function dispatch_source_set_registration_handler_f
729 * Sets the registration handler function for the given dispatch source.
732 * See dispatch_source_set_registration_handler() for more details.
735 * The dispatch source to modify.
736 * The result of passing NULL in this parameter is undefined.
739 * The registration handler function to submit to the source's target queue.
740 * The context parameter passed to the registration handler function is the
741 * current context of the dispatch source at the time the handler call is made.
743 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
744 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
746 dispatch_source_set_registration_handler_f(dispatch_source_t source
,
747 dispatch_function_t _Nullable handler
);
751 DISPATCH_ASSUME_NONNULL_END