2 * Copyright (c) 2008-2011 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_NONNULL_ALL 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_NONNULL2 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
339 * Returns the current queue.
341 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
342 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NOTHROW
344 dispatch_get_current_queue(void);
347 * @function dispatch_get_main_queue
350 * Returns the default queue that is bound to the main thread.
353 * In order to invoke blocks submitted to the main queue, the application must
354 * call dispatch_main(), NSApplicationMain(), or use a CFRunLoop on the main
358 * Returns the main queue. This queue is created automatically on behalf of
359 * the main thread before main() is called.
361 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
362 DISPATCH_EXPORT
struct dispatch_queue_s _dispatch_main_q
;
363 #define dispatch_get_main_queue() \
364 DISPATCH_GLOBAL_OBJECT(dispatch_queue_t, _dispatch_main_q)
367 * @typedef dispatch_queue_priority_t
368 * Type of dispatch_queue_priority
370 * @constant DISPATCH_QUEUE_PRIORITY_HIGH
371 * Items dispatched to the queue will run at high priority,
372 * i.e. the queue will be scheduled for execution before
373 * any default priority or low priority queue.
375 * @constant DISPATCH_QUEUE_PRIORITY_DEFAULT
376 * Items dispatched to the queue will run at the default
377 * priority, i.e. the queue will be scheduled for execution
378 * after all high priority queues have been scheduled, but
379 * before any low priority queues have been scheduled.
381 * @constant DISPATCH_QUEUE_PRIORITY_LOW
382 * Items dispatched to the queue will run at low priority,
383 * i.e. the queue will be scheduled for execution after all
384 * default priority and high priority queues have been
387 * @constant DISPATCH_QUEUE_PRIORITY_BACKGROUND
388 * Items dispatched to the queue will run at background priority, i.e. the queue
389 * will be scheduled for execution after all higher priority queues have been
390 * scheduled and the system will run items on this queue on a thread with
391 * background status as per setpriority(2) (i.e. disk I/O is throttled and the
392 * thread's scheduling priority is set to lowest value).
394 #define DISPATCH_QUEUE_PRIORITY_HIGH 2
395 #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
396 #define DISPATCH_QUEUE_PRIORITY_LOW (-2)
397 #define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN
399 typedef long dispatch_queue_priority_t
;
402 * @function dispatch_get_global_queue
405 * Returns a well-known global concurrent queue of a given priority level.
408 * The well-known global concurrent queues may not be modified. Calls to
409 * dispatch_suspend(), dispatch_resume(), dispatch_set_context(), etc., will
410 * have no effect when used with queues returned by this function.
413 * A priority defined in dispatch_queue_priority_t
416 * Reserved for future use. Passing any value other than zero may result in
417 * a NULL return value.
420 * Returns the requested global queue.
422 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
423 DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
425 dispatch_get_global_queue(dispatch_queue_priority_t priority
,
426 unsigned long flags
);
429 * @const DISPATCH_QUEUE_SERIAL
430 * @discussion A dispatch queue that invokes blocks serially in FIFO order.
432 #define DISPATCH_QUEUE_SERIAL NULL
435 * @const DISPATCH_QUEUE_CONCURRENT
436 * @discussion A dispatch queue that may invoke blocks concurrently and supports
437 * barrier blocks submitted with the dispatch barrier API.
439 #define DISPATCH_QUEUE_CONCURRENT \
440 DISPATCH_GLOBAL_OBJECT(dispatch_queue_attr_t, \
441 _dispatch_queue_attr_concurrent)
442 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
444 struct dispatch_queue_attr_s _dispatch_queue_attr_concurrent
;
447 * @function dispatch_queue_create
450 * Creates a new dispatch queue to which blocks may be submitted.
453 * Dispatch queues created with the DISPATCH_QUEUE_SERIAL or a NULL attribute
454 * invoke blocks serially in FIFO order.
456 * Dispatch queues created with the DISPATCH_QUEUE_CONCURRENT attribute may
457 * invoke blocks concurrently (similarly to the global concurrent queues, but
458 * potentially with more overhead), and support barrier blocks submitted with
459 * the dispatch barrier API, which e.g. enables the implementation of efficient
460 * reader-writer schemes.
462 * When a dispatch queue is no longer needed, it should be released with
463 * dispatch_release(). Note that any pending blocks submitted to a queue will
464 * hold a reference to that queue. Therefore a queue will not be deallocated
465 * until all pending blocks have finished.
467 * The target queue of a newly created dispatch queue is the default priority
468 * global concurrent queue.
471 * A string label to attach to the queue.
472 * This parameter is optional and may be NULL.
475 * DISPATCH_QUEUE_SERIAL or DISPATCH_QUEUE_CONCURRENT.
478 * The newly created dispatch queue.
480 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
481 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
484 dispatch_queue_create(const char *label
, dispatch_queue_attr_t attr
);
487 * @function dispatch_queue_get_label
490 * Returns the label of the queue that was specified when the
494 * The result of passing NULL in this parameter is undefined.
497 * The label of the queue. The result may be NULL.
499 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
500 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
503 dispatch_queue_get_label(dispatch_queue_t queue
);
506 * @const DISPATCH_TARGET_QUEUE_DEFAULT
507 * @discussion Constant to pass to the dispatch_set_target_queue() and
508 * dispatch_source_create() functions to indicate that the default target queue
509 * for the given object type should be used.
511 #define DISPATCH_TARGET_QUEUE_DEFAULT NULL
514 * @function dispatch_set_target_queue
517 * Sets the target queue for the given object.
520 * An object's target queue is responsible for processing the object.
522 * A dispatch queue's priority is inherited from its target queue. Use the
523 * dispatch_get_global_queue() function to obtain suitable target queue
524 * of the desired priority.
526 * Blocks submitted to a serial queue whose target queue is another serial
527 * queue will not be invoked concurrently with blocks submitted to the target
528 * queue or to any other queue with that same target queue.
530 * The result of introducing a cycle into the hierarchy of target queues is
533 * A dispatch source's target queue specifies where its event handler and
534 * cancellation handler blocks will be submitted.
536 * A dispatch I/O channel's target queue specifies where where its I/O
537 * operations are executed. If the channel's target queue's priority is set to
538 * DISPATCH_QUEUE_PRIORITY_BACKGROUND, then the I/O operations performed by
539 * dispatch_io_read() or dispatch_io_write() on that queue will be
540 * throttled when there is I/O contention.
542 * For all other dispatch object types, the only function of the target queue
543 * is to determine where an object's finalizer function is invoked.
546 * The object to modify.
547 * The result of passing NULL in this parameter is undefined.
550 * The new target queue for the object. The queue is retained, and the
551 * previous target queue, if any, is released.
552 * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, set the object's target queue
553 * to the default target queue for the given object type.
555 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
556 DISPATCH_EXPORT DISPATCH_NOTHROW
// DISPATCH_NONNULL1
558 dispatch_set_target_queue(dispatch_object_t object
, dispatch_queue_t queue
);
561 * @function dispatch_main
564 * Execute blocks submitted to the main queue.
567 * This function "parks" the main thread and waits for blocks to be submitted
568 * to the main queue. This function never returns.
570 * Applications that call NSApplicationMain() or CFRunLoopRun() on the
571 * main thread do not need to call dispatch_main().
573 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
574 DISPATCH_EXPORT DISPATCH_NOTHROW DISPATCH_NORETURN
579 * @function dispatch_after
582 * Schedule a block for execution on a given queue at a specified time.
585 * Passing DISPATCH_TIME_NOW as the "when" parameter is supported, but not as
586 * optimal as calling dispatch_async() instead. Passing DISPATCH_TIME_FOREVER
590 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
593 * A queue to which the given block will be submitted at the specified time.
594 * The result of passing NULL in this parameter is undefined.
597 * The block of code to execute.
598 * The result of passing NULL in this parameter is undefined.
601 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
602 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL3 DISPATCH_NOTHROW
604 dispatch_after(dispatch_time_t when
,
605 dispatch_queue_t queue
,
606 dispatch_block_t block
);
610 * @function dispatch_after_f
613 * Schedule a function for execution on a given queue at a specified time.
616 * See dispatch_after() for details.
619 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
622 * A queue to which the given function will be submitted at the specified time.
623 * The result of passing NULL in this parameter is undefined.
626 * The application-defined context parameter to pass to the function.
629 * The application-defined function to invoke on the target queue. The first
630 * parameter passed to this function is the context provided to
631 * dispatch_after_f().
632 * The result of passing NULL in this parameter is undefined.
634 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
635 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL4 DISPATCH_NOTHROW
637 dispatch_after_f(dispatch_time_t when
,
638 dispatch_queue_t queue
,
640 dispatch_function_t work
);
643 * @functiongroup Dispatch Barrier API
644 * The dispatch barrier API is a mechanism for submitting barrier blocks to a
645 * dispatch queue, analogous to the dispatch_async()/dispatch_sync() API.
646 * It enables the implementation of efficient reader/writer schemes.
647 * Barrier blocks only behave specially when submitted to queues created with
648 * the DISPATCH_QUEUE_CONCURRENT attribute; on such a queue, a barrier block
649 * will not run until all blocks submitted to the queue earlier have completed,
650 * and any blocks submitted to the queue after a barrier block will not run
651 * until the barrier block has completed.
652 * When submitted to a a global queue or to a queue not created with the
653 * DISPATCH_QUEUE_CONCURRENT attribute, barrier blocks behave identically to
654 * blocks submitted with the dispatch_async()/dispatch_sync() API.
658 * @function dispatch_barrier_async
661 * Submits a barrier block for asynchronous execution on a dispatch queue.
664 * Submits a block to a dispatch queue like dispatch_async(), but marks that
665 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
667 * See dispatch_async() for details.
670 * The target dispatch queue to which the block is submitted.
671 * The system will hold a reference on the target queue until the block
673 * The result of passing NULL in this parameter is undefined.
676 * The block to submit to the target dispatch queue. This function performs
677 * Block_copy() and Block_release() on behalf of callers.
678 * The result of passing NULL in this parameter is undefined.
681 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
682 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
684 dispatch_barrier_async(dispatch_queue_t queue
, dispatch_block_t block
);
688 * @function dispatch_barrier_async_f
691 * Submits a barrier function for asynchronous execution on a dispatch queue.
694 * Submits a function to a dispatch queue like dispatch_async_f(), but marks
695 * that function as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT
698 * See dispatch_async_f() for details.
701 * The target dispatch queue to which the function is submitted.
702 * The system will hold a reference on the target queue until the function
704 * The result of passing NULL in this parameter is undefined.
707 * The application-defined context parameter to pass to the function.
710 * The application-defined function to invoke on the target queue. The first
711 * parameter passed to this function is the context provided to
712 * dispatch_barrier_async_f().
713 * The result of passing NULL in this parameter is undefined.
715 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
716 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
718 dispatch_barrier_async_f(dispatch_queue_t queue
,
720 dispatch_function_t work
);
723 * @function dispatch_barrier_sync
726 * Submits a barrier block for synchronous execution on a dispatch queue.
729 * Submits a block to a dispatch queue like dispatch_sync(), but marks that
730 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
732 * See dispatch_sync() for details.
735 * The target dispatch queue to which the block is submitted.
736 * The result of passing NULL in this parameter is undefined.
739 * The block to be invoked on the target dispatch queue.
740 * The result of passing NULL in this parameter is undefined.
743 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
744 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
746 dispatch_barrier_sync(dispatch_queue_t queue
, dispatch_block_t block
);
750 * @function dispatch_barrier_sync_f
753 * Submits a barrier function for synchronous execution on a dispatch queue.
756 * Submits a function to a dispatch queue like dispatch_sync_f(), but marks that
757 * fuction as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
759 * See dispatch_sync_f() for details.
762 * The target dispatch queue to which the function is submitted.
763 * The result of passing NULL in this parameter is undefined.
766 * The application-defined context parameter to pass to the function.
769 * The application-defined function to invoke on the target queue. The first
770 * parameter passed to this function is the context provided to
771 * dispatch_barrier_sync_f().
772 * The result of passing NULL in this parameter is undefined.
774 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
775 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
777 dispatch_barrier_sync_f(dispatch_queue_t queue
,
779 dispatch_function_t work
);
782 * @functiongroup Dispatch queue-specific contexts
783 * This API allows different subsystems to associate context to a shared queue
784 * without risk of collision and to retrieve that context from blocks executing
785 * on that queue or any of its child queues in the target queue hierarchy.
789 * @function dispatch_queue_set_specific
792 * Associates a subsystem-specific context with a dispatch queue, for a key
793 * unique to the subsystem.
796 * The specified destructor will be invoked with the context on the default
797 * priority global concurrent queue when a new context is set for the same key,
798 * or after all references to the queue have been released.
801 * The dispatch queue to modify.
802 * The result of passing NULL in this parameter is undefined.
805 * The key to set the context for, typically a pointer to a static variable
806 * specific to the subsystem. Keys are only compared as pointers and never
807 * dereferenced. Passing a string constant directly is not recommended.
808 * The NULL key is reserved and attemps to set a context for it are ignored.
811 * The new subsystem-specific context for the object. This may be NULL.
814 * The destructor function pointer. This may be NULL and is ignored if context
817 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
818 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_NOTHROW
820 dispatch_queue_set_specific(dispatch_queue_t queue
, const void *key
,
821 void *context
, dispatch_function_t destructor
);
824 * @function dispatch_queue_get_specific
827 * Returns the subsystem-specific context associated with a dispatch queue, for
828 * a key unique to the subsystem.
831 * Returns the context for the specified key if it has been set on the specified
835 * The dispatch queue to query.
836 * The result of passing NULL in this parameter is undefined.
839 * The key to get the context for, typically a pointer to a static variable
840 * specific to the subsystem. Keys are only compared as pointers and never
841 * dereferenced. Passing a string constant directly is not recommended.
844 * The context for the specified key or NULL if no context was found.
846 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
847 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
850 dispatch_queue_get_specific(dispatch_queue_t queue
, const void *key
);
853 * @function dispatch_get_specific
856 * Returns the current subsystem-specific context for a key unique to the
860 * When called from a block executing on a queue, returns the context for the
861 * specified key if it has been set on the queue, otherwise returns the result
862 * of dispatch_get_specific() executed on the queue's target queue or NULL
863 * if the current queue is a global concurrent queue.
866 * The key to get the context for, typically a pointer to a static variable
867 * specific to the subsystem. Keys are only compared as pointers and never
868 * dereferenced. Passing a string constant directly is not recommended.
871 * The context for the specified key or NULL if no context was found.
873 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
874 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
877 dispatch_get_specific(const void *key
);