2 * Copyright (c) 2008-2012 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_QUEUE__
22 #define __DISPATCH_QUEUE__
24 #ifndef __DISPATCH_INDIRECT__
25 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
26 #include <dispatch/base.h> // for HeaderDoc
32 * Dispatch is an abstract model for expressing concurrency via simple but
35 * At the core, dispatch provides serial FIFO queues to which blocks may be
36 * submitted. Blocks submitted to these dispatch queues are invoked on a pool
37 * of threads fully managed by the system. No guarantee is made regarding
38 * which thread a block will be invoked on; however, it is guaranteed that only
39 * one block submitted to the FIFO dispatch queue will be invoked at a time.
41 * When multiple queues have blocks to be processed, the system is free to
42 * allocate additional threads to invoke the blocks concurrently. When the
43 * queues become empty, these threads are automatically released.
47 * @typedef dispatch_queue_t
50 * Dispatch queues invoke blocks submitted to them serially in FIFO order. A
51 * queue will only invoke one block at a time, but independent queues may each
52 * invoke their blocks concurrently with respect to each other.
55 * Dispatch queues are lightweight objects to which blocks may be submitted.
56 * The system manages a pool of threads which process dispatch queues and
57 * invoke blocks submitted to them.
59 * Conceptually a dispatch queue may have its own thread of execution, and
60 * interaction between queues is highly asynchronous.
62 * Dispatch queues are reference counted via calls to dispatch_retain() and
63 * dispatch_release(). Pending blocks submitted to a queue also hold a
64 * reference to the queue until they have finished. Once all references to a
65 * queue have been released, the queue will be deallocated by the system.
67 DISPATCH_DECL(dispatch_queue
);
70 * @typedef dispatch_queue_attr_t
73 * Attribute for dispatch queues.
75 DISPATCH_DECL(dispatch_queue_attr
);
78 * @typedef dispatch_block_t
81 * The prototype of blocks submitted to dispatch queues, which take no
82 * arguments and have no return value.
85 * The declaration of a block allocates storage on the stack. Therefore, this
86 * is an invalid construct:
88 * dispatch_block_t block;
91 * block = ^{ printf("true\n"); };
93 * block = ^{ printf("false\n"); };
95 * block(); // unsafe!!!
97 * What is happening behind the scenes:
100 * struct Block __tmp_1 = ...; // setup details
103 * struct Block __tmp_2 = ...; // setup details
107 * As the example demonstrates, the address of a stack variable is escaping the
108 * scope in which it is allocated. That is a classic C bug.
111 typedef void (^dispatch_block_t
)(void);
117 * @function dispatch_async
120 * Submits a block for asynchronous execution on a dispatch queue.
123 * The dispatch_async() function is the fundamental mechanism for submitting
124 * blocks to a dispatch queue.
126 * Calls to dispatch_async() always return immediately after the block has
127 * been submitted, and never wait for the block to be invoked.
129 * The target queue determines whether the block will be invoked serially or
130 * concurrently with respect to other blocks submitted to that same queue.
131 * Serial queues are processed concurrently with respect to each other.
134 * The target dispatch queue to which the block is submitted.
135 * The system will hold a reference on the target queue until the block
137 * The result of passing NULL in this parameter is undefined.
140 * The block to submit to the target dispatch queue. This function performs
141 * Block_copy() and Block_release() on behalf of callers.
142 * The result of passing NULL in this parameter is undefined.
145 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
146 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
148 dispatch_async(dispatch_queue_t queue
, dispatch_block_t block
);
152 * @function dispatch_async_f
155 * Submits a function for asynchronous execution on a dispatch queue.
158 * See dispatch_async() for details.
161 * The target dispatch queue to which the function is submitted.
162 * The system will hold a reference on the target queue until the function
164 * The result of passing NULL in this parameter is undefined.
167 * The application-defined context parameter to pass to the function.
170 * The application-defined function to invoke on the target queue. The first
171 * parameter passed to this function is the context provided to
172 * dispatch_async_f().
173 * The result of passing NULL in this parameter is undefined.
175 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
176 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
178 dispatch_async_f(dispatch_queue_t queue
,
180 dispatch_function_t work
);
183 * @function dispatch_sync
186 * Submits a block for synchronous execution on a dispatch queue.
189 * Submits a block to a dispatch queue like dispatch_async(), however
190 * dispatch_sync() will not return until the block has finished.
192 * Calls to dispatch_sync() targeting the current queue will result
193 * in dead-lock. Use of dispatch_sync() is also subject to the same
194 * multi-party dead-lock problems that may result from the use of a mutex.
195 * Use of dispatch_async() is preferred.
197 * Unlike dispatch_async(), no retain is performed on the target queue. Because
198 * calls to this function are synchronous, the dispatch_sync() "borrows" the
199 * reference of the caller.
201 * As an optimization, dispatch_sync() invokes the block on the current
202 * thread when possible.
205 * The target dispatch queue to which the block is submitted.
206 * The result of passing NULL in this parameter is undefined.
209 * The block to be invoked on the target dispatch queue.
210 * The result of passing NULL in this parameter is undefined.
213 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
214 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
216 dispatch_sync(dispatch_queue_t queue
, dispatch_block_t block
);
220 * @function dispatch_sync_f
223 * Submits a function for synchronous execution on a dispatch queue.
226 * See dispatch_sync() for details.
229 * The target dispatch queue to which the function is submitted.
230 * The result of passing NULL in this parameter is undefined.
233 * The application-defined context parameter to pass to the function.
236 * The application-defined function to invoke on the target queue. The first
237 * parameter passed to this function is the context provided to
239 * The result of passing NULL in this parameter is undefined.
241 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
242 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
244 dispatch_sync_f(dispatch_queue_t queue
,
246 dispatch_function_t work
);
249 * @function dispatch_apply
252 * Submits a block to a dispatch queue for multiple invocations.
255 * Submits a block to a dispatch queue for multiple invocations. This function
256 * waits for the task block to complete before returning. If the target queue
257 * is concurrent, the block may be invoked concurrently, and it must therefore
260 * Each invocation of the block will be passed the current index of iteration.
263 * The number of iterations to perform.
266 * The target dispatch queue to which the block is submitted.
267 * The result of passing NULL in this parameter is undefined.
270 * The block to be invoked the specified number of iterations.
271 * The result of passing NULL in this parameter is undefined.
274 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
275 DISPATCH_EXPORT DISPATCH_NONNULL3 DISPATCH_NOTHROW
277 dispatch_apply(size_t iterations
, dispatch_queue_t queue
,
278 void (^block
)(size_t));
282 * @function dispatch_apply_f
285 * Submits a function to a dispatch queue for multiple invocations.
288 * See dispatch_apply() for details.
291 * The number of iterations to perform.
294 * The target dispatch queue to which the function is submitted.
295 * The result of passing NULL in this parameter is undefined.
298 * The application-defined context parameter to pass to the function.
301 * The application-defined function to invoke on the target queue. The first
302 * parameter passed to this function is the context provided to
303 * dispatch_apply_f(). The second parameter passed to this function is the
304 * current index of iteration.
305 * The result of passing NULL in this parameter is undefined.
307 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
308 DISPATCH_EXPORT DISPATCH_NONNULL4 DISPATCH_NOTHROW
310 dispatch_apply_f(size_t iterations
, dispatch_queue_t queue
,
312 void (*work
)(void *, size_t));
315 * @function dispatch_get_current_queue
318 * Returns the queue on which the currently executing block is running.
321 * Returns the queue on which the currently executing block is running.
323 * When dispatch_get_current_queue() is called outside of the context of a
324 * submitted block, it will return the default concurrent queue.
326 * Recommended for debugging and logging purposes only:
327 * The code must not make any assumptions about the queue returned, unless it
328 * is one of the global queues or a queue the code has itself created.
329 * The code must not assume that synchronous execution onto a queue is safe
330 * from deadlock if that queue is not the one returned by
331 * dispatch_get_current_queue().
333 * When dispatch_get_current_queue() is called on the main thread, it may
334 * or may not return the same value as dispatch_get_main_queue(). Comparing
335 * the two is not a valid way to test whether code is executing on the
338 * This function is deprecated and will be removed in a future release.
341 * Returns the current queue.
343 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6
,__MAC_10_9
,__IPHONE_4_0
,__IPHONE_6_0
)
344 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NOTHROW
346 dispatch_get_current_queue(void);
349 * @function dispatch_get_main_queue
352 * Returns the default queue that is bound to the main thread.
355 * In order to invoke blocks submitted to the main queue, the application must
356 * call dispatch_main(), NSApplicationMain(), or use a CFRunLoop on the main
360 * Returns the main queue. This queue is created automatically on behalf of
361 * the main thread before main() is called.
363 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
364 DISPATCH_EXPORT
struct dispatch_queue_s _dispatch_main_q
;
365 #define dispatch_get_main_queue() \
366 DISPATCH_GLOBAL_OBJECT(dispatch_queue_t, _dispatch_main_q)
369 * @typedef dispatch_queue_priority_t
370 * Type of dispatch_queue_priority
372 * @constant DISPATCH_QUEUE_PRIORITY_HIGH
373 * Items dispatched to the queue will run at high priority,
374 * i.e. the queue will be scheduled for execution before
375 * any default priority or low priority queue.
377 * @constant DISPATCH_QUEUE_PRIORITY_DEFAULT
378 * Items dispatched to the queue will run at the default
379 * priority, i.e. the queue will be scheduled for execution
380 * after all high priority queues have been scheduled, but
381 * before any low priority queues have been scheduled.
383 * @constant DISPATCH_QUEUE_PRIORITY_LOW
384 * Items dispatched to the queue will run at low priority,
385 * i.e. the queue will be scheduled for execution after all
386 * default priority and high priority queues have been
389 * @constant DISPATCH_QUEUE_PRIORITY_BACKGROUND
390 * Items dispatched to the queue will run at background priority, i.e. the queue
391 * will be scheduled for execution after all higher priority queues have been
392 * scheduled and the system will run items on this queue on a thread with
393 * background status as per setpriority(2) (i.e. disk I/O is throttled and the
394 * thread's scheduling priority is set to lowest value).
396 #define DISPATCH_QUEUE_PRIORITY_HIGH 2
397 #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
398 #define DISPATCH_QUEUE_PRIORITY_LOW (-2)
399 #define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN
401 typedef long dispatch_queue_priority_t
;
404 * @function dispatch_get_global_queue
407 * Returns a well-known global concurrent queue of a given priority level.
410 * The well-known global concurrent queues may not be modified. Calls to
411 * dispatch_suspend(), dispatch_resume(), dispatch_set_context(), etc., will
412 * have no effect when used with queues returned by this function.
415 * A priority defined in dispatch_queue_priority_t
418 * Reserved for future use. Passing any value other than zero may result in
419 * a NULL return value.
422 * Returns the requested global queue.
424 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
425 DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
427 dispatch_get_global_queue(dispatch_queue_priority_t priority
,
428 unsigned long flags
);
431 * @const DISPATCH_QUEUE_SERIAL
432 * @discussion A dispatch queue that invokes blocks serially in FIFO order.
434 #define DISPATCH_QUEUE_SERIAL NULL
437 * @const DISPATCH_QUEUE_CONCURRENT
438 * @discussion A dispatch queue that may invoke blocks concurrently and supports
439 * barrier blocks submitted with the dispatch barrier API.
441 #define DISPATCH_QUEUE_CONCURRENT \
442 DISPATCH_GLOBAL_OBJECT(dispatch_queue_attr_t, \
443 _dispatch_queue_attr_concurrent)
444 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
446 struct dispatch_queue_attr_s _dispatch_queue_attr_concurrent
;
449 * @function dispatch_queue_create
452 * Creates a new dispatch queue to which blocks may be submitted.
455 * Dispatch queues created with the DISPATCH_QUEUE_SERIAL or a NULL attribute
456 * invoke blocks serially in FIFO order.
458 * Dispatch queues created with the DISPATCH_QUEUE_CONCURRENT attribute may
459 * invoke blocks concurrently (similarly to the global concurrent queues, but
460 * potentially with more overhead), and support barrier blocks submitted with
461 * the dispatch barrier API, which e.g. enables the implementation of efficient
462 * reader-writer schemes.
464 * When a dispatch queue is no longer needed, it should be released with
465 * dispatch_release(). Note that any pending blocks submitted to a queue will
466 * hold a reference to that queue. Therefore a queue will not be deallocated
467 * until all pending blocks have finished.
469 * The target queue of a newly created dispatch queue is the default priority
470 * global concurrent queue.
473 * A string label to attach to the queue.
474 * This parameter is optional and may be NULL.
477 * DISPATCH_QUEUE_SERIAL or DISPATCH_QUEUE_CONCURRENT.
480 * The newly created dispatch queue.
482 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
483 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
486 dispatch_queue_create(const char *label
, dispatch_queue_attr_t attr
);
489 * @const DISPATCH_CURRENT_QUEUE_LABEL
490 * @discussion Constant to pass to the dispatch_queue_get_label() function to
491 * retrieve the label of the current queue.
493 #define DISPATCH_CURRENT_QUEUE_LABEL NULL
496 * @function dispatch_queue_get_label
499 * Returns the label of the given queue, as specified when the queue was
500 * created, or the empty string if a NULL label was specified.
502 * Passing DISPATCH_CURRENT_QUEUE_LABEL will return the label of the current
506 * The queue to query, or DISPATCH_CURRENT_QUEUE_LABEL.
509 * The label of the queue.
511 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
512 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NOTHROW
514 dispatch_queue_get_label(dispatch_queue_t queue
);
517 * @const DISPATCH_TARGET_QUEUE_DEFAULT
518 * @discussion Constant to pass to the dispatch_set_target_queue() and
519 * dispatch_source_create() functions to indicate that the default target queue
520 * for the given object type should be used.
522 #define DISPATCH_TARGET_QUEUE_DEFAULT NULL
525 * @function dispatch_set_target_queue
528 * Sets the target queue for the given object.
531 * An object's target queue is responsible for processing the object.
533 * A dispatch queue's priority is inherited from its target queue. Use the
534 * dispatch_get_global_queue() function to obtain suitable target queue
535 * of the desired priority.
537 * Blocks submitted to a serial queue whose target queue is another serial
538 * queue will not be invoked concurrently with blocks submitted to the target
539 * queue or to any other queue with that same target queue.
541 * The result of introducing a cycle into the hierarchy of target queues is
544 * A dispatch source's target queue specifies where its event handler and
545 * cancellation handler blocks will be submitted.
547 * A dispatch I/O channel's target queue specifies where where its I/O
548 * operations are executed. If the channel's target queue's priority is set to
549 * DISPATCH_QUEUE_PRIORITY_BACKGROUND, then the I/O operations performed by
550 * dispatch_io_read() or dispatch_io_write() on that queue will be
551 * throttled when there is I/O contention.
553 * For all other dispatch object types, the only function of the target queue
554 * is to determine where an object's finalizer function is invoked.
557 * The object to modify.
558 * The result of passing NULL in this parameter is undefined.
561 * The new target queue for the object. The queue is retained, and the
562 * previous target queue, if any, is released.
563 * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, set the object's target queue
564 * to the default target queue for the given object type.
566 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
567 DISPATCH_EXPORT DISPATCH_NOTHROW
// DISPATCH_NONNULL1
569 dispatch_set_target_queue(dispatch_object_t object
, dispatch_queue_t queue
);
572 * @function dispatch_main
575 * Execute blocks submitted to the main queue.
578 * This function "parks" the main thread and waits for blocks to be submitted
579 * to the main queue. This function never returns.
581 * Applications that call NSApplicationMain() or CFRunLoopRun() on the
582 * main thread do not need to call dispatch_main().
584 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
585 DISPATCH_EXPORT DISPATCH_NOTHROW DISPATCH_NORETURN
590 * @function dispatch_after
593 * Schedule a block for execution on a given queue at a specified time.
596 * Passing DISPATCH_TIME_NOW as the "when" parameter is supported, but not as
597 * optimal as calling dispatch_async() instead. Passing DISPATCH_TIME_FOREVER
601 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
604 * A queue to which the given block will be submitted at the specified time.
605 * The result of passing NULL in this parameter is undefined.
608 * The block of code to execute.
609 * The result of passing NULL in this parameter is undefined.
612 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
613 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL3 DISPATCH_NOTHROW
615 dispatch_after(dispatch_time_t when
,
616 dispatch_queue_t queue
,
617 dispatch_block_t block
);
621 * @function dispatch_after_f
624 * Schedule a function for execution on a given queue at a specified time.
627 * See dispatch_after() for details.
630 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
633 * A queue to which the given function will be submitted at the specified time.
634 * The result of passing NULL in this parameter is undefined.
637 * The application-defined context parameter to pass to the function.
640 * The application-defined function to invoke on the target queue. The first
641 * parameter passed to this function is the context provided to
642 * dispatch_after_f().
643 * The result of passing NULL in this parameter is undefined.
645 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
646 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL4 DISPATCH_NOTHROW
648 dispatch_after_f(dispatch_time_t when
,
649 dispatch_queue_t queue
,
651 dispatch_function_t work
);
654 * @functiongroup Dispatch Barrier API
655 * The dispatch barrier API is a mechanism for submitting barrier blocks to a
656 * dispatch queue, analogous to the dispatch_async()/dispatch_sync() API.
657 * It enables the implementation of efficient reader/writer schemes.
658 * Barrier blocks only behave specially when submitted to queues created with
659 * the DISPATCH_QUEUE_CONCURRENT attribute; on such a queue, a barrier block
660 * will not run until all blocks submitted to the queue earlier have completed,
661 * and any blocks submitted to the queue after a barrier block will not run
662 * until the barrier block has completed.
663 * When submitted to a a global queue or to a queue not created with the
664 * DISPATCH_QUEUE_CONCURRENT attribute, barrier blocks behave identically to
665 * blocks submitted with the dispatch_async()/dispatch_sync() API.
669 * @function dispatch_barrier_async
672 * Submits a barrier block for asynchronous execution on a dispatch queue.
675 * Submits a block to a dispatch queue like dispatch_async(), but marks that
676 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
678 * See dispatch_async() for details.
681 * The target dispatch queue to which the block is submitted.
682 * The system will hold a reference on the target queue until the block
684 * The result of passing NULL in this parameter is undefined.
687 * The block to submit to the target dispatch queue. This function performs
688 * Block_copy() and Block_release() on behalf of callers.
689 * The result of passing NULL in this parameter is undefined.
692 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
693 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
695 dispatch_barrier_async(dispatch_queue_t queue
, dispatch_block_t block
);
699 * @function dispatch_barrier_async_f
702 * Submits a barrier function for asynchronous execution on a dispatch queue.
705 * Submits a function to a dispatch queue like dispatch_async_f(), but marks
706 * that function as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT
709 * See dispatch_async_f() for details.
712 * The target dispatch queue to which the function is submitted.
713 * The system will hold a reference on the target queue until the function
715 * The result of passing NULL in this parameter is undefined.
718 * The application-defined context parameter to pass to the function.
721 * The application-defined function to invoke on the target queue. The first
722 * parameter passed to this function is the context provided to
723 * dispatch_barrier_async_f().
724 * The result of passing NULL in this parameter is undefined.
726 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
727 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
729 dispatch_barrier_async_f(dispatch_queue_t queue
,
731 dispatch_function_t work
);
734 * @function dispatch_barrier_sync
737 * Submits a barrier block for synchronous execution on a dispatch queue.
740 * Submits a block to a dispatch queue like dispatch_sync(), but marks that
741 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
743 * See dispatch_sync() for details.
746 * The target dispatch queue to which the block is submitted.
747 * The result of passing NULL in this parameter is undefined.
750 * The block to be invoked on the target dispatch queue.
751 * The result of passing NULL in this parameter is undefined.
754 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
755 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
757 dispatch_barrier_sync(dispatch_queue_t queue
, dispatch_block_t block
);
761 * @function dispatch_barrier_sync_f
764 * Submits a barrier function for synchronous execution on a dispatch queue.
767 * Submits a function to a dispatch queue like dispatch_sync_f(), but marks that
768 * fuction as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
770 * See dispatch_sync_f() for details.
773 * The target dispatch queue to which the function is submitted.
774 * The result of passing NULL in this parameter is undefined.
777 * The application-defined context parameter to pass to the function.
780 * The application-defined function to invoke on the target queue. The first
781 * parameter passed to this function is the context provided to
782 * dispatch_barrier_sync_f().
783 * The result of passing NULL in this parameter is undefined.
785 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
786 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
788 dispatch_barrier_sync_f(dispatch_queue_t queue
,
790 dispatch_function_t work
);
793 * @functiongroup Dispatch queue-specific contexts
794 * This API allows different subsystems to associate context to a shared queue
795 * without risk of collision and to retrieve that context from blocks executing
796 * on that queue or any of its child queues in the target queue hierarchy.
800 * @function dispatch_queue_set_specific
803 * Associates a subsystem-specific context with a dispatch queue, for a key
804 * unique to the subsystem.
807 * The specified destructor will be invoked with the context on the default
808 * priority global concurrent queue when a new context is set for the same key,
809 * or after all references to the queue have been released.
812 * The dispatch queue to modify.
813 * The result of passing NULL in this parameter is undefined.
816 * The key to set the context for, typically a pointer to a static variable
817 * specific to the subsystem. Keys are only compared as pointers and never
818 * dereferenced. Passing a string constant directly is not recommended.
819 * The NULL key is reserved and attemps to set a context for it are ignored.
822 * The new subsystem-specific context for the object. This may be NULL.
825 * The destructor function pointer. This may be NULL and is ignored if context
828 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
829 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_NOTHROW
831 dispatch_queue_set_specific(dispatch_queue_t queue
, const void *key
,
832 void *context
, dispatch_function_t destructor
);
835 * @function dispatch_queue_get_specific
838 * Returns the subsystem-specific context associated with a dispatch queue, for
839 * a key unique to the subsystem.
842 * Returns the context for the specified key if it has been set on the specified
846 * The dispatch queue to query.
847 * The result of passing NULL in this parameter is undefined.
850 * The key to get the context for, typically a pointer to a static variable
851 * specific to the subsystem. Keys are only compared as pointers and never
852 * dereferenced. Passing a string constant directly is not recommended.
855 * The context for the specified key or NULL if no context was found.
857 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
858 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
861 dispatch_queue_get_specific(dispatch_queue_t queue
, const void *key
);
864 * @function dispatch_get_specific
867 * Returns the current subsystem-specific context for a key unique to the
871 * When called from a block executing on a queue, returns the context for the
872 * specified key if it has been set on the queue, otherwise returns the result
873 * of dispatch_get_specific() executed on the queue's target queue or NULL
874 * if the current queue is a global concurrent queue.
877 * The key to get the context for, typically a pointer to a static variable
878 * specific to the subsystem. Keys are only compared as pointers and never
879 * dereferenced. Passing a string constant directly is not recommended.
882 * The context for the specified key or NULL if no context was found.
884 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
885 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
888 dispatch_get_specific(const void *key
);