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>
40 * The dispatch framework provides a suite of interfaces for monitoring low-
41 * level system objects (file descriptors, Mach ports, signals, VFS nodes, etc.)
42 * for activity and automatically submitting event handler blocks to dispatch
43 * queues when such activity occurs.
45 * This suite of interfaces is known as the Dispatch Source API.
49 * @typedef dispatch_source_t
52 * Dispatch sources are used to automatically submit event handler blocks to
53 * dispatch queues in response to external events.
55 DISPATCH_DECL(dispatch_source
);
60 * @typedef dispatch_source_type_t
63 * Constants of this type represent the class of low-level system object that
64 * is being monitored by the dispatch source. Constants of this type are
65 * passed as a parameter to dispatch_source_create() and determine how the
66 * handle argument is interpreted (i.e. as a file descriptor, mach port,
67 * signal number, process identifer, etc.), and how the mask arugment is
70 typedef const struct dispatch_source_type_s
*dispatch_source_type_t
;
74 #define DISPATCH_SOURCE_TYPE_DECL(name) \
75 DISPATCH_EXPORT const struct dispatch_source_type_s \
76 _dispatch_source_type_##name
78 #define DISPATCH_SOURCE_TYPE_DECL(name) \
79 DISPATCH_EXPORT struct dispatch_source_type_s _dispatch_source_type_##name
83 * @const DISPATCH_SOURCE_TYPE_DATA_ADD
84 * @discussion A dispatch source that coalesces data obtained via calls to
85 * dispatch_source_merge_data(). An ADD is used to coalesce the data.
86 * The handle is unused (pass zero for now).
87 * The mask is unused (pass zero for now).
89 #define DISPATCH_SOURCE_TYPE_DATA_ADD (&_dispatch_source_type_data_add)
90 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
91 DISPATCH_SOURCE_TYPE_DECL(data_add
);
94 * @const DISPATCH_SOURCE_TYPE_DATA_OR
95 * @discussion A dispatch source that coalesces data obtained via calls to
96 * dispatch_source_merge_data(). A bitwise OR is used to coalesce the data.
97 * The handle is unused (pass zero for now).
98 * The mask is unused (pass zero for now).
100 #define DISPATCH_SOURCE_TYPE_DATA_OR (&_dispatch_source_type_data_or)
101 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
102 DISPATCH_SOURCE_TYPE_DECL(data_or
);
105 * @const DISPATCH_SOURCE_TYPE_MACH_SEND
106 * @discussion A dispatch source that monitors a Mach port for dead name
107 * notifications (send right no longer has any corresponding receive right).
108 * The handle is a Mach port with a send or send-once right (mach_port_t).
109 * The mask is a mask of desired events from dispatch_source_mach_send_flags_t.
111 #define DISPATCH_SOURCE_TYPE_MACH_SEND (&_dispatch_source_type_mach_send)
112 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
113 DISPATCH_SOURCE_TYPE_DECL(mach_send
);
116 * @const DISPATCH_SOURCE_TYPE_MACH_RECV
117 * @discussion A dispatch source that monitors a Mach port for pending messages.
118 * The handle is a Mach port with a receive right (mach_port_t).
119 * The mask is unused (pass zero for now).
121 #define DISPATCH_SOURCE_TYPE_MACH_RECV (&_dispatch_source_type_mach_recv)
122 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
123 DISPATCH_SOURCE_TYPE_DECL(mach_recv
);
126 * @const DISPATCH_SOURCE_TYPE_MEMORYPRESSURE
127 * @discussion A dispatch source that monitors the system for changes in
128 * memory pressure condition.
129 * The handle is unused (pass zero for now).
130 * The mask is a mask of desired events from
131 * dispatch_source_memorypressure_flags_t.
133 #define DISPATCH_SOURCE_TYPE_MEMORYPRESSURE \
134 (&_dispatch_source_type_memorypressure)
135 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_8_0
)
136 DISPATCH_SOURCE_TYPE_DECL(memorypressure
);
139 * @const DISPATCH_SOURCE_TYPE_PROC
140 * @discussion A dispatch source that monitors an external process for events
141 * defined by dispatch_source_proc_flags_t.
142 * The handle is a process identifier (pid_t).
143 * The mask is a mask of desired events from dispatch_source_proc_flags_t.
145 #define DISPATCH_SOURCE_TYPE_PROC (&_dispatch_source_type_proc)
146 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
147 DISPATCH_SOURCE_TYPE_DECL(proc
);
150 * @const DISPATCH_SOURCE_TYPE_READ
151 * @discussion A dispatch source that monitors a file descriptor for pending
152 * bytes available to be read.
153 * The handle is a file descriptor (int).
154 * The mask is unused (pass zero for now).
156 #define DISPATCH_SOURCE_TYPE_READ (&_dispatch_source_type_read)
157 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
158 DISPATCH_SOURCE_TYPE_DECL(read
);
161 * @const DISPATCH_SOURCE_TYPE_SIGNAL
162 * @discussion A dispatch source that monitors the current process for signals.
163 * The handle is a signal number (int).
164 * The mask is unused (pass zero for now).
166 #define DISPATCH_SOURCE_TYPE_SIGNAL (&_dispatch_source_type_signal)
167 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
168 DISPATCH_SOURCE_TYPE_DECL(signal
);
171 * @const DISPATCH_SOURCE_TYPE_TIMER
172 * @discussion A dispatch source that submits the event handler block based
174 * The handle is unused (pass zero for now).
175 * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
177 #define DISPATCH_SOURCE_TYPE_TIMER (&_dispatch_source_type_timer)
178 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
179 DISPATCH_SOURCE_TYPE_DECL(timer
);
182 * @const DISPATCH_SOURCE_TYPE_VNODE
183 * @discussion A dispatch source that monitors a file descriptor for events
184 * defined by dispatch_source_vnode_flags_t.
185 * The handle is a file descriptor (int).
186 * The mask is a mask of desired events from dispatch_source_vnode_flags_t.
188 #define DISPATCH_SOURCE_TYPE_VNODE (&_dispatch_source_type_vnode)
189 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
190 DISPATCH_SOURCE_TYPE_DECL(vnode
);
193 * @const DISPATCH_SOURCE_TYPE_WRITE
194 * @discussion A dispatch source that monitors a file descriptor for available
195 * buffer space to write bytes.
196 * The handle is a file descriptor (int).
197 * The mask is unused (pass zero for now).
199 #define DISPATCH_SOURCE_TYPE_WRITE (&_dispatch_source_type_write)
200 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
201 DISPATCH_SOURCE_TYPE_DECL(write
);
204 * @typedef dispatch_source_mach_send_flags_t
205 * Type of dispatch_source_mach_send flags
207 * @constant DISPATCH_MACH_SEND_DEAD
208 * The receive right corresponding to the given send right was destroyed.
210 #define DISPATCH_MACH_SEND_DEAD 0x1
212 typedef unsigned long dispatch_source_mach_send_flags_t
;
215 * @typedef dispatch_source_memorypressure_flags_t
216 * Type of dispatch_source_memorypressure flags
218 * @constant DISPATCH_MEMORYPRESSURE_NORMAL
219 * The system memory pressure condition has returned to normal.
221 * @constant DISPATCH_MEMORYPRESSURE_WARN
222 * The system memory pressure condition has changed to warning.
224 * @constant DISPATCH_MEMORYPRESSURE_CRITICAL
225 * The system memory pressure condition has changed to critical.
228 * Elevated memory pressure is a system-wide condition that applications
229 * registered for this source should react to by changing their future memory
230 * use behavior, e.g. by reducing cache sizes of newly initiated operations
231 * until memory pressure returns back to normal.
232 * NOTE: applications should NOT traverse and discard existing caches for past
233 * operations when the system memory pressure enters an elevated state, as that
234 * is likely to trigger VM operations that will further aggravate system memory
238 #define DISPATCH_MEMORYPRESSURE_NORMAL 0x01
239 #define DISPATCH_MEMORYPRESSURE_WARN 0x02
240 #define DISPATCH_MEMORYPRESSURE_CRITICAL 0x04
242 typedef unsigned long dispatch_source_memorypressure_flags_t
;
245 * @typedef dispatch_source_proc_flags_t
246 * Type of dispatch_source_proc flags
248 * @constant DISPATCH_PROC_EXIT
249 * The process has exited (perhaps cleanly, perhaps not).
251 * @constant DISPATCH_PROC_FORK
252 * The process has created one or more child processes.
254 * @constant DISPATCH_PROC_EXEC
255 * The process has become another executable image via
256 * exec*() or posix_spawn*().
258 * @constant DISPATCH_PROC_SIGNAL
259 * A Unix signal was delivered to the process.
261 #define DISPATCH_PROC_EXIT 0x80000000
262 #define DISPATCH_PROC_FORK 0x40000000
263 #define DISPATCH_PROC_EXEC 0x20000000
264 #define DISPATCH_PROC_SIGNAL 0x08000000
266 typedef unsigned long dispatch_source_proc_flags_t
;
269 * @typedef dispatch_source_vnode_flags_t
270 * Type of dispatch_source_vnode flags
272 * @constant DISPATCH_VNODE_DELETE
273 * The filesystem object was deleted from the namespace.
275 * @constant DISPATCH_VNODE_WRITE
276 * The filesystem object data changed.
278 * @constant DISPATCH_VNODE_EXTEND
279 * The filesystem object changed in size.
281 * @constant DISPATCH_VNODE_ATTRIB
282 * The filesystem object metadata changed.
284 * @constant DISPATCH_VNODE_LINK
285 * The filesystem object link count changed.
287 * @constant DISPATCH_VNODE_RENAME
288 * The filesystem object was renamed in the namespace.
290 * @constant DISPATCH_VNODE_REVOKE
291 * The filesystem object was revoked.
294 #define DISPATCH_VNODE_DELETE 0x1
295 #define DISPATCH_VNODE_WRITE 0x2
296 #define DISPATCH_VNODE_EXTEND 0x4
297 #define DISPATCH_VNODE_ATTRIB 0x8
298 #define DISPATCH_VNODE_LINK 0x10
299 #define DISPATCH_VNODE_RENAME 0x20
300 #define DISPATCH_VNODE_REVOKE 0x40
302 typedef unsigned long dispatch_source_vnode_flags_t
;
305 * @typedef dispatch_source_timer_flags_t
306 * Type of dispatch_source_timer flags
308 * @constant DISPATCH_TIMER_STRICT
309 * Specifies that the system should make a best effort to strictly observe the
310 * leeway value specified for the timer via dispatch_source_set_timer(), even
311 * if that value is smaller than the default leeway value that would be applied
312 * to the timer otherwise. A minimal amount of leeway will be applied to the
313 * timer even if this flag is specified.
315 * CAUTION: Use of this flag may override power-saving techniques employed by
316 * the system and cause higher power consumption, so it must be used with care
317 * and only when absolutely necessary.
320 #define DISPATCH_TIMER_STRICT 0x1
322 typedef unsigned long dispatch_source_timer_flags_t
;
326 * @function dispatch_source_create
329 * Creates a new dispatch source to monitor low-level system objects and auto-
330 * matically submit a handler block to a dispatch queue in response to events.
333 * Dispatch sources are not reentrant. Any events received while the dispatch
334 * source is suspended or while the event handler block is currently executing
335 * will be coalesced and delivered after the dispatch source is resumed or the
336 * event handler block has returned.
338 * Dispatch sources are created in a suspended state. After creating the
339 * source and setting any desired attributes (i.e. the handler, context, etc.),
340 * a call must be made to dispatch_resume() in order to begin event delivery.
343 * Declares the type of the dispatch source. Must be one of the defined
344 * dispatch_source_type_t constants.
346 * The underlying system handle to monitor. The interpretation of this argument
347 * is determined by the constant provided in the type parameter.
349 * A mask of flags specifying which events are desired. The interpretation of
350 * this argument is determined by the constant provided in the type parameter.
352 * The dispatch queue to which the event handler block will be submitted.
353 * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, the source will submit the event
354 * handler block to the default priority global queue.
356 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
357 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
360 dispatch_source_create(dispatch_source_type_t type
,
363 dispatch_queue_t queue
);
366 * @function dispatch_source_set_event_handler
369 * Sets the event handler block for the given dispatch source.
372 * The dispatch source to modify.
373 * The result of passing NULL in this parameter is undefined.
376 * The event handler block to submit to the source's target queue.
379 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
380 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
382 dispatch_source_set_event_handler(dispatch_source_t source
,
383 dispatch_block_t handler
);
384 #endif /* __BLOCKS__ */
387 * @function dispatch_source_set_event_handler_f
390 * Sets the event handler function for the given dispatch source.
393 * The dispatch source to modify.
394 * The result of passing NULL in this parameter is undefined.
397 * The event handler function to submit to the source's target queue.
398 * The context parameter passed to the event handler function is the current
399 * context of the dispatch source at the time the handler call is made.
400 * The result of passing NULL in this parameter is undefined.
402 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
403 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
405 dispatch_source_set_event_handler_f(dispatch_source_t source
,
406 dispatch_function_t handler
);
409 * @function dispatch_source_set_cancel_handler
412 * Sets the cancellation handler block for the given dispatch source.
415 * The cancellation handler (if specified) will be submitted to the source's
416 * target queue in response to a call to dispatch_source_cancel() once the
417 * system has released all references to the source's underlying handle and
418 * the source's event handler block has returned.
421 * A cancellation handler is required for file descriptor and mach port based
422 * sources in order to safely close the descriptor or destroy the port. Closing
423 * the descriptor or port before the cancellation handler may result in a race
424 * condition. If a new descriptor is allocated with the same value as the
425 * recently closed descriptor while the source's event handler is still running,
426 * the event handler may read/write data to the wrong descriptor.
429 * The dispatch source to modify.
430 * The result of passing NULL in this parameter is undefined.
433 * The cancellation handler block to submit to the source's target queue.
436 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
437 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
439 dispatch_source_set_cancel_handler(dispatch_source_t source
,
440 dispatch_block_t handler
);
441 #endif /* __BLOCKS__ */
444 * @function dispatch_source_set_cancel_handler_f
447 * Sets the cancellation handler function for the given dispatch source.
450 * See dispatch_source_set_cancel_handler() for more details.
453 * The dispatch source to modify.
454 * The result of passing NULL in this parameter is undefined.
457 * The cancellation handler function to submit to the source's target queue.
458 * The context parameter passed to the event handler function is the current
459 * context of the dispatch source at the time the handler call is made.
461 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
462 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
464 dispatch_source_set_cancel_handler_f(dispatch_source_t source
,
465 dispatch_function_t handler
);
468 * @function dispatch_source_cancel
471 * Asynchronously cancel the dispatch source, preventing any further invocation
472 * of its event handler block.
475 * Cancellation prevents any further invocation of the event handler block for
476 * the specified dispatch source, but does not interrupt an event handler
477 * block that is already in progress.
479 * The cancellation handler is submitted to the source's target queue once the
480 * the source's event handler has finished, indicating it is now safe to close
481 * the source's handle (i.e. file descriptor or mach port).
483 * See dispatch_source_set_cancel_handler() for more information.
486 * The dispatch source to be canceled.
487 * The result of passing NULL in this parameter is undefined.
489 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
490 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
492 dispatch_source_cancel(dispatch_source_t source
);
495 * @function dispatch_source_testcancel
498 * Tests whether the given dispatch source has been canceled.
501 * The dispatch source to be tested.
502 * The result of passing NULL in this parameter is undefined.
505 * Non-zero if canceled and zero if not canceled.
507 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
508 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
511 dispatch_source_testcancel(dispatch_source_t source
);
514 * @function dispatch_source_get_handle
517 * Returns the underlying system handle associated with this dispatch source.
520 * The result of passing NULL in this parameter is undefined.
523 * The return value should be interpreted according to the type of the dispatch
524 * source, and may be one of the following handles:
526 * DISPATCH_SOURCE_TYPE_DATA_ADD: n/a
527 * DISPATCH_SOURCE_TYPE_DATA_OR: n/a
528 * DISPATCH_SOURCE_TYPE_MACH_SEND: mach port (mach_port_t)
529 * DISPATCH_SOURCE_TYPE_MACH_RECV: mach port (mach_port_t)
530 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE n/a
531 * DISPATCH_SOURCE_TYPE_PROC: process identifier (pid_t)
532 * DISPATCH_SOURCE_TYPE_READ: file descriptor (int)
533 * DISPATCH_SOURCE_TYPE_SIGNAL: signal number (int)
534 * DISPATCH_SOURCE_TYPE_TIMER: n/a
535 * DISPATCH_SOURCE_TYPE_VNODE: file descriptor (int)
536 * DISPATCH_SOURCE_TYPE_WRITE: file descriptor (int)
538 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
539 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
542 dispatch_source_get_handle(dispatch_source_t source
);
545 * @function dispatch_source_get_mask
548 * Returns the mask of events monitored by the dispatch source.
551 * The result of passing NULL in this parameter is undefined.
554 * The return value should be interpreted according to the type of the dispatch
555 * source, and may be one of the following flag sets:
557 * DISPATCH_SOURCE_TYPE_DATA_ADD: n/a
558 * DISPATCH_SOURCE_TYPE_DATA_OR: n/a
559 * DISPATCH_SOURCE_TYPE_MACH_SEND: dispatch_source_mach_send_flags_t
560 * DISPATCH_SOURCE_TYPE_MACH_RECV: n/a
561 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE dispatch_source_memorypressure_flags_t
562 * DISPATCH_SOURCE_TYPE_PROC: dispatch_source_proc_flags_t
563 * DISPATCH_SOURCE_TYPE_READ: n/a
564 * DISPATCH_SOURCE_TYPE_SIGNAL: n/a
565 * DISPATCH_SOURCE_TYPE_TIMER: dispatch_source_timer_flags_t
566 * DISPATCH_SOURCE_TYPE_VNODE: dispatch_source_vnode_flags_t
567 * DISPATCH_SOURCE_TYPE_WRITE: n/a
569 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
570 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
573 dispatch_source_get_mask(dispatch_source_t source
);
576 * @function dispatch_source_get_data
579 * Returns pending data for the dispatch source.
582 * This function is intended to be called from within the event handler block.
583 * The result of calling this function outside of the event handler callback is
587 * The result of passing NULL in this parameter is undefined.
590 * The return value should be interpreted according to the type of the dispatch
591 * source, and may be one of the following:
593 * DISPATCH_SOURCE_TYPE_DATA_ADD: application defined data
594 * DISPATCH_SOURCE_TYPE_DATA_OR: application defined data
595 * DISPATCH_SOURCE_TYPE_MACH_SEND: dispatch_source_mach_send_flags_t
596 * DISPATCH_SOURCE_TYPE_MACH_RECV: n/a
597 * DISPATCH_SOURCE_TYPE_MEMORYPRESSURE dispatch_source_memorypressure_flags_t
598 * DISPATCH_SOURCE_TYPE_PROC: dispatch_source_proc_flags_t
599 * DISPATCH_SOURCE_TYPE_READ: estimated bytes available to read
600 * DISPATCH_SOURCE_TYPE_SIGNAL: number of signals delivered since
601 * the last handler invocation
602 * DISPATCH_SOURCE_TYPE_TIMER: number of times the timer has fired
603 * since the last handler invocation
604 * DISPATCH_SOURCE_TYPE_VNODE: dispatch_source_vnode_flags_t
605 * DISPATCH_SOURCE_TYPE_WRITE: estimated buffer space available
607 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
608 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
611 dispatch_source_get_data(dispatch_source_t source
);
614 * @function dispatch_source_merge_data
617 * Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or
618 * DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its
622 * The result of passing NULL in this parameter is undefined.
625 * The value to coalesce with the pending data using a logical OR or an ADD
626 * as specified by the dispatch source type. A value of zero has no effect
627 * and will not result in the submission of the event handler block.
629 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
630 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
632 dispatch_source_merge_data(dispatch_source_t source
, unsigned long value
);
635 * @function dispatch_source_set_timer
638 * Sets a start time, interval, and leeway value for a timer source.
641 * Once this function returns, any pending source data accumulated for the
642 * previous timer values has been cleared; the next fire of the timer will
643 * occur at 'start', and every 'interval' nanoseconds thereafter until the
644 * timer source is canceled.
646 * Any fire of the timer may be delayed by the system in order to improve power
647 * consumption and system performance. The upper limit to the allowable delay
648 * may be configured with the 'leeway' argument, the lower limit is under the
649 * control of the system.
651 * For the initial timer fire at 'start', the upper limit to the allowable
652 * delay is set to 'leeway' nanoseconds. For the subsequent timer fires at
653 * 'start' + N * 'interval', the upper limit is MIN('leeway','interval'/2).
655 * The lower limit to the allowable delay may vary with process state such as
656 * visibility of application UI. If the specified timer source was created with
657 * a mask of DISPATCH_TIMER_STRICT, the system will make a best effort to
658 * strictly observe the provided 'leeway' value even if it is smaller than the
659 * current lower limit. Note that a minimal amount of delay is to be expected
660 * even if this flag is specified.
662 * The 'start' argument also determines which clock will be used for the timer:
663 * If 'start' is DISPATCH_TIME_NOW or was created with dispatch_time(3), the
664 * timer is based on mach_absolute_time(). If 'start' was created with
665 * dispatch_walltime(3), the timer is based on gettimeofday(3).
667 * Calling this function has no effect if the timer source has already been
671 * The start time of the timer. See dispatch_time() and dispatch_walltime()
672 * for more information.
675 * The nanosecond interval for the timer. Use DISPATCH_TIME_FOREVER for a
679 * The nanosecond leeway for the timer.
681 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
682 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
684 dispatch_source_set_timer(dispatch_source_t source
,
685 dispatch_time_t start
,
690 * @function dispatch_source_set_registration_handler
693 * Sets the registration handler block for the given dispatch source.
696 * The registration handler (if specified) will be submitted to the source's
697 * target queue once the corresponding kevent() has been registered with the
698 * system, following the initial dispatch_resume() of the source.
700 * If a source is already registered when the registration handler is set, the
701 * registration handler will be invoked immediately.
704 * The dispatch source to modify.
705 * The result of passing NULL in this parameter is undefined.
708 * The registration handler block to submit to the source's target queue.
711 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
712 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
714 dispatch_source_set_registration_handler(dispatch_source_t source
,
715 dispatch_block_t handler
);
716 #endif /* __BLOCKS__ */
719 * @function dispatch_source_set_registration_handler_f
722 * Sets the registration handler function for the given dispatch source.
725 * See dispatch_source_set_registration_handler() for more details.
728 * The dispatch source to modify.
729 * The result of passing NULL in this parameter is undefined.
732 * The registration handler function to submit to the source's target queue.
733 * The context parameter passed to the registration handler function is the
734 * current context of the dispatch source at the time the handler call is made.
736 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
737 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NOTHROW
739 dispatch_source_set_registration_handler_f(dispatch_source_t source
,
740 dispatch_function_t handler
);