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().
334 * Returns the current queue.
336 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
337 DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NOTHROW
339 dispatch_get_current_queue(void);
342 * @function dispatch_get_main_queue
345 * Returns the default queue that is bound to the main thread.
348 * In order to invoke blocks submitted to the main queue, the application must
349 * call dispatch_main(), NSApplicationMain(), or use a CFRunLoop on the main
353 * Returns the main queue. This queue is created automatically on behalf of
354 * the main thread before main() is called.
356 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
357 DISPATCH_EXPORT
struct dispatch_queue_s _dispatch_main_q
;
358 #define dispatch_get_main_queue() (&_dispatch_main_q)
361 * @typedef dispatch_queue_priority_t
362 * Type of dispatch_queue_priority
364 * @constant DISPATCH_QUEUE_PRIORITY_HIGH
365 * Items dispatched to the queue will run at high priority,
366 * i.e. the queue will be scheduled for execution before
367 * any default priority or low priority queue.
369 * @constant DISPATCH_QUEUE_PRIORITY_DEFAULT
370 * Items dispatched to the queue will run at the default
371 * priority, i.e. the queue will be scheduled for execution
372 * after all high priority queues have been scheduled, but
373 * before any low priority queues have been scheduled.
375 * @constant DISPATCH_QUEUE_PRIORITY_LOW
376 * Items dispatched to the queue will run at low priority,
377 * i.e. the queue will be scheduled for execution after all
378 * default priority and high priority queues have been
381 * @constant DISPATCH_QUEUE_PRIORITY_BACKGROUND
382 * Items dispatched to the queue will run at background priority, i.e. the queue
383 * will be scheduled for execution after all higher priority queues have been
384 * scheduled and the system will run items on this queue on a thread with
385 * background status as per setpriority(2) (i.e. disk I/O is throttled and the
386 * thread's scheduling priority is set to lowest value).
388 #define DISPATCH_QUEUE_PRIORITY_HIGH 2
389 #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
390 #define DISPATCH_QUEUE_PRIORITY_LOW (-2)
391 #define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN
393 typedef long dispatch_queue_priority_t
;
396 * @function dispatch_get_global_queue
399 * Returns a well-known global concurrent queue of a given priority level.
402 * The well-known global concurrent queues may not be modified. Calls to
403 * dispatch_suspend(), dispatch_resume(), dispatch_set_context(), etc., will
404 * have no effect when used with queues returned by this function.
407 * A priority defined in dispatch_queue_priority_t
410 * Reserved for future use. Passing any value other than zero may result in
411 * a NULL return value.
414 * Returns the requested global queue.
416 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
417 DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
419 dispatch_get_global_queue(dispatch_queue_priority_t priority
,
420 unsigned long flags
);
423 * @const DISPATCH_QUEUE_SERIAL
424 * @discussion A dispatch queue that invokes blocks serially in FIFO order.
426 #define DISPATCH_QUEUE_SERIAL NULL
429 * @const DISPATCH_QUEUE_CONCURRENT
430 * @discussion A dispatch queue that may invoke blocks concurrently and supports
431 * barrier blocks submitted with the dispatch barrier API.
433 #define DISPATCH_QUEUE_CONCURRENT (&_dispatch_queue_attr_concurrent)
434 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
436 struct dispatch_queue_attr_s _dispatch_queue_attr_concurrent
;
439 * @function dispatch_queue_create
442 * Creates a new dispatch queue to which blocks may be submitted.
445 * Dispatch queues created with the DISPATCH_QUEUE_SERIAL or a NULL attribute
446 * invoke blocks serially in FIFO order.
448 * Dispatch queues created with the DISPATCH_QUEUE_CONCURRENT attribute may
449 * invoke blocks concurrently (similarly to the global concurrent queues, but
450 * potentially with more overhead), and support barrier blocks submitted with
451 * the dispatch barrier API, which e.g. enables the implementation of efficient
452 * reader-writer schemes.
454 * When a dispatch queue is no longer needed, it should be released with
455 * dispatch_release(). Note that any pending blocks submitted to a queue will
456 * hold a reference to that queue. Therefore a queue will not be deallocated
457 * until all pending blocks have finished.
459 * The target queue of a newly created dispatch queue is the default priority
460 * global concurrent queue.
463 * A string label to attach to the queue.
464 * This parameter is optional and may be NULL.
467 * DISPATCH_QUEUE_SERIAL or DISPATCH_QUEUE_CONCURRENT.
470 * The newly created dispatch queue.
472 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
473 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_WARN_RESULT DISPATCH_NOTHROW
475 dispatch_queue_create(const char *label
, dispatch_queue_attr_t attr
);
478 * @function dispatch_queue_get_label
481 * Returns the label of the queue that was specified when the
485 * The result of passing NULL in this parameter is undefined.
488 * The label of the queue. The result may be NULL.
490 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
491 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
494 dispatch_queue_get_label(dispatch_queue_t queue
);
497 * @const DISPATCH_TARGET_QUEUE_DEFAULT
498 * @discussion Constant to pass to the dispatch_set_target_queue() and
499 * dispatch_source_create() functions to indicate that the default target queue
500 * for the given object type should be used.
502 #define DISPATCH_TARGET_QUEUE_DEFAULT NULL
505 * @function dispatch_set_target_queue
508 * Sets the target queue for the given object.
511 * An object's target queue is responsible for processing the object.
513 * A dispatch queue's priority is inherited from its target queue. Use the
514 * dispatch_get_global_queue() function to obtain suitable target queue
515 * of the desired priority.
517 * Blocks submitted to a serial queue whose target queue is another serial
518 * queue will not be invoked concurrently with blocks submitted to the target
519 * queue or to any other queue with that same target queue.
521 * The result of introducing a cycle into the hierarchy of target queues is
524 * A dispatch source's target queue specifies where its event handler and
525 * cancellation handler blocks will be submitted.
527 * A dispatch I/O channel's target queue specifies where where its I/O
528 * operations are executed.
530 * For all other dispatch object types, the only function of the target queue
531 * is to determine where an object's finalizer function is invoked.
534 * The object to modify.
535 * The result of passing NULL in this parameter is undefined.
538 * The new target queue for the object. The queue is retained, and the
539 * previous target queue, if any, is released.
540 * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, set the object's target queue
541 * to the default target queue for the given object type.
543 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
544 DISPATCH_EXPORT DISPATCH_NOTHROW
// DISPATCH_NONNULL1
546 dispatch_set_target_queue(dispatch_object_t object
, dispatch_queue_t queue
);
549 * @function dispatch_main
552 * Execute blocks submitted to the main queue.
555 * This function "parks" the main thread and waits for blocks to be submitted
556 * to the main queue. This function never returns.
558 * Applications that call NSApplicationMain() or CFRunLoopRun() on the
559 * main thread do not need to call dispatch_main().
561 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
562 DISPATCH_EXPORT DISPATCH_NOTHROW DISPATCH_NORETURN
567 * @function dispatch_after
570 * Schedule a block for execution on a given queue at a specified time.
573 * Passing DISPATCH_TIME_NOW as the "when" parameter is supported, but not as
574 * optimal as calling dispatch_async() instead. Passing DISPATCH_TIME_FOREVER
578 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
581 * A queue to which the given block will be submitted at the specified time.
582 * The result of passing NULL in this parameter is undefined.
585 * The block of code to execute.
586 * The result of passing NULL in this parameter is undefined.
589 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
590 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL3 DISPATCH_NOTHROW
592 dispatch_after(dispatch_time_t when
,
593 dispatch_queue_t queue
,
594 dispatch_block_t block
);
598 * @function dispatch_after_f
601 * Schedule a function for execution on a given queue at a specified time.
604 * See dispatch_after() for details.
607 * A temporal milestone returned by dispatch_time() or dispatch_walltime().
610 * A queue to which the given function will be submitted at the specified time.
611 * The result of passing NULL in this parameter is undefined.
614 * The application-defined context parameter to pass to the function.
617 * The application-defined function to invoke on the target queue. The first
618 * parameter passed to this function is the context provided to
619 * dispatch_after_f().
620 * The result of passing NULL in this parameter is undefined.
622 __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
)
623 DISPATCH_EXPORT DISPATCH_NONNULL2 DISPATCH_NONNULL4 DISPATCH_NOTHROW
625 dispatch_after_f(dispatch_time_t when
,
626 dispatch_queue_t queue
,
628 dispatch_function_t work
);
631 * @functiongroup Dispatch Barrier API
632 * The dispatch barrier API is a mechanism for submitting barrier blocks to a
633 * dispatch queue, analogous to the dispatch_async()/dispatch_sync() API.
634 * It enables the implementation of efficient reader/writer schemes.
635 * Barrier blocks only behave specially when submitted to queues created with
636 * the DISPATCH_QUEUE_CONCURRENT attribute; on such a queue, a barrier block
637 * will not run until all blocks submitted to the queue earlier have completed,
638 * and any blocks submitted to the queue after a barrier block will not run
639 * until the barrier block has completed.
640 * When submitted to a a global queue or to a queue not created with the
641 * DISPATCH_QUEUE_CONCURRENT attribute, barrier blocks behave identically to
642 * blocks submitted with the dispatch_async()/dispatch_sync() API.
646 * @function dispatch_barrier_async
649 * Submits a barrier block for asynchronous execution on a dispatch queue.
652 * Submits a block to a dispatch queue like dispatch_async(), but marks that
653 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
655 * See dispatch_async() for details.
658 * The target dispatch queue to which the block is submitted.
659 * The system will hold a reference on the target queue until the block
661 * The result of passing NULL in this parameter is undefined.
664 * The block to submit to the target dispatch queue. This function performs
665 * Block_copy() and Block_release() on behalf of callers.
666 * The result of passing NULL in this parameter is undefined.
669 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
670 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
672 dispatch_barrier_async(dispatch_queue_t queue
, dispatch_block_t block
);
676 * @function dispatch_barrier_async_f
679 * Submits a barrier function for asynchronous execution on a dispatch queue.
682 * Submits a function to a dispatch queue like dispatch_async_f(), but marks
683 * that function as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT
686 * See dispatch_async_f() for details.
689 * The target dispatch queue to which the function is submitted.
690 * The system will hold a reference on the target queue until the function
692 * The result of passing NULL in this parameter is undefined.
695 * The application-defined context parameter to pass to the function.
698 * The application-defined function to invoke on the target queue. The first
699 * parameter passed to this function is the context provided to
700 * dispatch_barrier_async_f().
701 * The result of passing NULL in this parameter is undefined.
703 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
704 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
706 dispatch_barrier_async_f(dispatch_queue_t queue
,
708 dispatch_function_t work
);
711 * @function dispatch_barrier_sync
714 * Submits a barrier block for synchronous execution on a dispatch queue.
717 * Submits a block to a dispatch queue like dispatch_sync(), but marks that
718 * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
720 * See dispatch_sync() for details.
723 * The target dispatch queue to which the block is submitted.
724 * The result of passing NULL in this parameter is undefined.
727 * The block to be invoked on the target dispatch queue.
728 * The result of passing NULL in this parameter is undefined.
731 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
732 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
734 dispatch_barrier_sync(dispatch_queue_t queue
, dispatch_block_t block
);
738 * @function dispatch_barrier_sync_f
741 * Submits a barrier function for synchronous execution on a dispatch queue.
744 * Submits a function to a dispatch queue like dispatch_sync_f(), but marks that
745 * fuction as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues).
747 * See dispatch_sync_f() for details.
750 * The target dispatch queue to which the function is submitted.
751 * The result of passing NULL in this parameter is undefined.
754 * The application-defined context parameter to pass to the function.
757 * The application-defined function to invoke on the target queue. The first
758 * parameter passed to this function is the context provided to
759 * dispatch_barrier_sync_f().
760 * The result of passing NULL in this parameter is undefined.
762 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_4_3
)
763 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
765 dispatch_barrier_sync_f(dispatch_queue_t queue
,
767 dispatch_function_t work
);
770 * @functiongroup Dispatch queue-specific contexts
771 * This API allows different subsystems to associate context to a shared queue
772 * without risk of collision and to retrieve that context from blocks executing
773 * on that queue or any of its child queues in the target queue hierarchy.
777 * @function dispatch_queue_set_specific
780 * Associates a subsystem-specific context with a dispatch queue, for a key
781 * unique to the subsystem.
784 * The specified destructor will be invoked with the context on the default
785 * priority global concurrent queue when a new context is set for the same key,
786 * or after all references to the queue have been released.
789 * The dispatch queue to modify.
790 * The result of passing NULL in this parameter is undefined.
793 * The key to set the context for, typically a pointer to a static variable
794 * specific to the subsystem. Keys are only compared as pointers and never
795 * dereferenced. Passing a string constant directly is not recommended.
796 * The NULL key is reserved and attemps to set a context for it are ignored.
799 * The new subsystem-specific context for the object. This may be NULL.
802 * The destructor function pointer. This may be NULL and is ignored if context
805 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
806 DISPATCH_EXPORT DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_NOTHROW
808 dispatch_queue_set_specific(dispatch_queue_t queue
, const void *key
,
809 void *context
, dispatch_function_t destructor
);
812 * @function dispatch_queue_get_specific
815 * Returns the subsystem-specific context associated with a dispatch queue, for
816 * a key unique to the subsystem.
819 * Returns the context for the specified key if it has been set on the specified
823 * The dispatch queue to query.
824 * The result of passing NULL in this parameter is undefined.
827 * The key to get the context for, typically a pointer to a static variable
828 * specific to the subsystem. Keys are only compared as pointers and never
829 * dereferenced. Passing a string constant directly is not recommended.
832 * The context for the specified key or NULL if no context was found.
834 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
835 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
838 dispatch_queue_get_specific(dispatch_queue_t queue
, const void *key
);
841 * @function dispatch_get_specific
844 * Returns the current subsystem-specific context for a key unique to the
848 * When called from a block executing on a queue, returns the context for the
849 * specified key if it has been set on the queue, otherwise returns the result
850 * of dispatch_get_specific() executed on the queue's target queue or NULL
851 * if the current queue is a global concurrent queue.
854 * The key to get the context for, typically a pointer to a static variable
855 * specific to the subsystem. Keys are only compared as pointers and never
856 * dereferenced. Passing a string constant directly is not recommended.
859 * The context for the specified key or NULL if no context was found.
861 __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
)
862 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_PURE DISPATCH_WARN_RESULT
865 dispatch_get_specific(const void *key
);