GCD

来源:互联网 发布:java二叉树遍历 编辑:程序博客网 时间:2024/05/26 17:43
import Dispatch/* * Copyright (c) 2008-2014 Apple Inc. All rights reserved. * * @APPLE_APACHE_LICENSE_HEADER_START@ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @APPLE_APACHE_LICENSE_HEADER_END@ */// for HeaderDoc/*! * @header * * Dispatch is an abstract model for expressing concurrency via simple but * powerful API. * * At the core, dispatch provides serial FIFO queues to which blocks may be * submitted. Blocks submitted to these dispatch queues are invoked on a pool * of threads fully managed by the system. No guarantee is made regarding * which thread a block will be invoked on; however, it is guaranteed that only * one block submitted to the FIFO dispatch queue will be invoked at a time. * * When multiple queues have blocks to be processed, the system is free to * allocate additional threads to invoke the blocks concurrently. When the * queues become empty, these threads are automatically released. *//*! * @typedef dispatch_queue_t * * @abstract * Dispatch queues invoke blocks submitted to them serially in FIFO order. A * queue will only invoke one block at a time, but independent queues may each * invoke their blocks concurrently with respect to each other. * * @discussion * Dispatch queues are lightweight objects to which blocks may be submitted. * The system manages a pool of threads which process dispatch queues and * invoke blocks submitted to them. * * Conceptually a dispatch queue may have its own thread of execution, and * interaction between queues is highly asynchronous. * * Dispatch queues are reference counted via calls to dispatch_retain() and * dispatch_release(). Pending blocks submitted to a queue also hold a * reference to the queue until they have finished. Once all references to a * queue have been released, the queue will be deallocated by the system. */protocol OS_dispatch_queue : OS_dispatch_object {}typealias dispatch_queue_t = NSObject/*! * @function dispatch_async * * @abstract * Submits a block for asynchronous execution on a dispatch queue. * * @discussion * The dispatch_async() function is the fundamental mechanism for submitting * blocks to a dispatch queue. * * Calls to dispatch_async() always return immediately after the block has * been submitted, and never wait for the block to be invoked. * * The target queue determines whether the block will be invoked serially or * concurrently with respect to other blocks submitted to that same queue. * Serial queues are processed concurrently with respect to each other. * * @param queue * The target dispatch queue to which the block is submitted. * The system will hold a reference on the target queue until the block * has finished. * The result of passing NULL in this parameter is undefined. * * @param block * The block to submit to the target dispatch queue. This function performs * Block_copy() and Block_release() on behalf of callers. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_async(queue: dispatch_queue_t!, block: dispatch_block_t!)/*! * @function dispatch_async_f * * @abstract * Submits a function for asynchronous execution on a dispatch queue. * * @discussion * See dispatch_async() for details. * * @param queue * The target dispatch queue to which the function is submitted. * The system will hold a reference on the target queue until the function * has returned. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_async_f(). * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_async_f(queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: dispatch_function_t)/*! * @function dispatch_sync * * @abstract * Submits a block for synchronous execution on a dispatch queue. * * @discussion * Submits a block to a dispatch queue like dispatch_async(), however * dispatch_sync() will not return until the block has finished. * * Calls to dispatch_sync() targeting the current queue will result * in dead-lock. Use of dispatch_sync() is also subject to the same * multi-party dead-lock problems that may result from the use of a mutex. * Use of dispatch_async() is preferred. * * Unlike dispatch_async(), no retain is performed on the target queue. Because * calls to this function are synchronous, the dispatch_sync() "borrows" the * reference of the caller. * * As an optimization, dispatch_sync() invokes the block on the current * thread when possible. * * @param queue * The target dispatch queue to which the block is submitted. * The result of passing NULL in this parameter is undefined. * * @param block * The block to be invoked on the target dispatch queue. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_sync(queue: dispatch_queue_t!, block: dispatch_block_t!)/*! * @function dispatch_sync_f * * @abstract * Submits a function for synchronous execution on a dispatch queue. * * @discussion * See dispatch_sync() for details. * * @param queue * The target dispatch queue to which the function is submitted. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_sync_f(). * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_sync_f(queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: dispatch_function_t)/*! * @function dispatch_apply * * @abstract * Submits a block to a dispatch queue for multiple invocations. * * @discussion * Submits a block to a dispatch queue for multiple invocations. This function * waits for the task block to complete before returning. If the target queue * is concurrent, the block may be invoked concurrently, and it must therefore * be reentrant safe. * * Each invocation of the block will be passed the current index of iteration. * * @param iterations * The number of iterations to perform. * * @param queue * The target dispatch queue to which the block is submitted. * The result of passing NULL in this parameter is undefined. * * @param block * The block to be invoked the specified number of iterations. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_apply(iterations: UInt, queue: dispatch_queue_t!, block: ((UInt) -> Void)!)/*! * @function dispatch_apply_f * * @abstract * Submits a function to a dispatch queue for multiple invocations. * * @discussion * See dispatch_apply() for details. * * @param iterations * The number of iterations to perform. * * @param queue * The target dispatch queue to which the function is submitted. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_apply_f(). The second parameter passed to this function is the * current index of iteration. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_apply_f(iterations: UInt, queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: CFunctionPointer<((UnsafeMutablePointer<Void>, UInt) -> Void)>)/*! * @function dispatch_get_current_queue * * @abstract * Returns the queue on which the currently executing block is running. * * @discussion * Returns the queue on which the currently executing block is running. * * When dispatch_get_current_queue() is called outside of the context of a * submitted block, it will return the default concurrent queue. * * Recommended for debugging and logging purposes only: * The code must not make any assumptions about the queue returned, unless it * is one of the global queues or a queue the code has itself created. * The code must not assume that synchronous execution onto a queue is safe * from deadlock if that queue is not the one returned by * dispatch_get_current_queue(). * * When dispatch_get_current_queue() is called on the main thread, it may * or may not return the same value as dispatch_get_main_queue(). Comparing * the two is not a valid way to test whether code is executing on the * main thread. * * This function is deprecated and will be removed in a future release. * * @result * Returns the current queue. *//*! * @function dispatch_get_main_queue * * @abstract * Returns the default queue that is bound to the main thread. * * @discussion * In order to invoke blocks submitted to the main queue, the application must * call dispatch_main(), NSApplicationMain(), or use a CFRunLoop on the main * thread. * * @result * Returns the main queue. This queue is created automatically on behalf of * the main thread before main() is called. */func dispatch_get_main_queue() -> dispatch_queue_t!/*! * @typedef dispatch_queue_priority_t * Type of dispatch_queue_priority * * @constant DISPATCH_QUEUE_PRIORITY_HIGH * Items dispatched to the queue will run at high priority, * i.e. the queue will be scheduled for execution before * any default priority or low priority queue. * * @constant DISPATCH_QUEUE_PRIORITY_DEFAULT * Items dispatched to the queue will run at the default * priority, i.e. the queue will be scheduled for execution * after all high priority queues have been scheduled, but * before any low priority queues have been scheduled. * * @constant DISPATCH_QUEUE_PRIORITY_LOW * Items dispatched to the queue will run at low priority, * i.e. the queue will be scheduled for execution after all * default priority and high priority queues have been * scheduled. * * @constant DISPATCH_QUEUE_PRIORITY_BACKGROUND * Items dispatched to the queue will run at background priority, i.e. the queue * will be scheduled for execution after all higher priority queues have been * scheduled and the system will run items on this queue on a thread with * background status as per setpriority(2) (i.e. disk I/O is throttled and the * thread's scheduling priority is set to lowest value). */var DISPATCH_QUEUE_PRIORITY_HIGH: Int32 { get }var DISPATCH_QUEUE_PRIORITY_DEFAULT: Int32 { get }var DISPATCH_QUEUE_PRIORITY_LOW: Int32 { get }var DISPATCH_QUEUE_PRIORITY_BACKGROUND: Int32 { get }typealias dispatch_queue_priority_t = Int/*! * @typedef dispatch_qos_class_t * Alias for qos_class_t type. */typealias dispatch_qos_class_t = qos_class_t/*! * @function dispatch_get_global_queue * * @abstract * Returns a well-known global concurrent queue of a given quality of service * class. * * @discussion * The well-known global concurrent queues may not be modified. Calls to * dispatch_suspend(), dispatch_resume(), dispatch_set_context(), etc., will * have no effect when used with queues returned by this function. * * @param identifier * A quality of service class defined in qos_class_t or a priority defined in * dispatch_queue_priority_t. * * It is recommended to use quality of service class values to identify the * well-known global concurrent queues: *  - QOS_CLASS_USER_INTERACTIVE *  - QOS_CLASS_USER_INITIATED *  - QOS_CLASS_DEFAULT *  - QOS_CLASS_UTILITY *  - QOS_CLASS_BACKGROUND * * The global concurrent queues may still be identified by their priority, * which map to the following QOS classes: *  - DISPATCH_QUEUE_PRIORITY_HIGH:         QOS_CLASS_USER_INITIATED *  - DISPATCH_QUEUE_PRIORITY_DEFAULT:      QOS_CLASS_DEFAULT *  - DISPATCH_QUEUE_PRIORITY_LOW:          QOS_CLASS_UTILITY *  - DISPATCH_QUEUE_PRIORITY_BACKGROUND:   QOS_CLASS_BACKGROUND * * @param flags * Reserved for future use. Passing any value other than zero may result in * a NULL return value. * * @result * Returns the requested global queue or NULL if the requested global queue * does not exist. */@availability(iOS, introduced=4.0)func dispatch_get_global_queue(identifier: Int, flags: UInt) -> dispatch_queue_t!/*! * @typedef dispatch_queue_attr_t * * @abstract * Attribute for dispatch queues. */protocol OS_dispatch_queue_attr : OS_dispatch_object {}typealias dispatch_queue_attr_t = NSObject/*! * @const DISPATCH_QUEUE_SERIAL * @discussion A dispatch queue that invokes blocks serially in FIFO order. *//*! * @const DISPATCH_QUEUE_CONCURRENT * @discussion A dispatch queue that may invoke blocks concurrently and supports * barrier blocks submitted with the dispatch barrier API. *//*! * @function dispatch_queue_attr_make_with_qos_class * * @abstract * Returns an attribute value which may be provided to dispatch_queue_create() * in order to assign a QOS class and relative priority to the queue. * * @discussion * When specified in this manner, the QOS class and relative priority take * precedence over those inherited from the dispatch queue's target queue (if * any) as long that does not result in a lower QOS class and relative priority. * * The global queue priorities map to the following QOS classes: *  - DISPATCH_QUEUE_PRIORITY_HIGH:         QOS_CLASS_USER_INITIATED *  - DISPATCH_QUEUE_PRIORITY_DEFAULT:      QOS_CLASS_DEFAULT *  - DISPATCH_QUEUE_PRIORITY_LOW:          QOS_CLASS_UTILITY *  - DISPATCH_QUEUE_PRIORITY_BACKGROUND:   QOS_CLASS_BACKGROUND * * Example: * <code> *dispatch_queue_t queue; *dispatch_queue_attr_t attr; *attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, *QOS_CLASS_UTILITY, 0); *queue = dispatch_queue_create("com.example.myqueue", attr); * </code> * * @param attr * A queue attribute value to be combined with the QOS class, or NULL. * * @param qos_class * A QOS class value: *  - QOS_CLASS_USER_INTERACTIVE *  - QOS_CLASS_USER_INITIATED *  - QOS_CLASS_DEFAULT *  - QOS_CLASS_UTILITY *  - QOS_CLASS_BACKGROUND * Passing any other value results in NULL being returned. * * @param relative_priority * A relative priority within the QOS class. This value is a negative * offset from the maximum supported scheduler priority for the given class. * Passing a value greater than zero or less than QOS_MIN_RELATIVE_PRIORITY * results in NULL being returned. * * @return * Returns an attribute value which may be provided to dispatch_queue_create(), * or NULL if an invalid QOS class was requested. * The new value combines the attributes specified by the 'attr' parameter and * the new QOS class and relative priority. */@availability(iOS, introduced=8.0)func dispatch_queue_attr_make_with_qos_class(attr: dispatch_queue_attr_t!, qos_class: dispatch_qos_class_t, relative_priority: Int32) -> dispatch_queue_attr_t!/*! * @function dispatch_queue_create * * @abstract * Creates a new dispatch queue to which blocks may be submitted. * * @discussion * Dispatch queues created with the DISPATCH_QUEUE_SERIAL or a NULL attribute * invoke blocks serially in FIFO order. * * Dispatch queues created with the DISPATCH_QUEUE_CONCURRENT attribute may * invoke blocks concurrently (similarly to the global concurrent queues, but * potentially with more overhead), and support barrier blocks submitted with * the dispatch barrier API, which e.g. enables the implementation of efficient * reader-writer schemes. * * When a dispatch queue is no longer needed, it should be released with * dispatch_release(). Note that any pending blocks submitted to a queue will * hold a reference to that queue. Therefore a queue will not be deallocated * until all pending blocks have finished. * * Passing the result of the dispatch_queue_attr_make_with_qos_class() function * to the attr parameter of this function allows a quality of service class and * relative priority to be specified for the newly created queue. * The quality of service class so specified takes precedence over the quality * of service class of the newly created dispatch queue's target queue (if any) * as long that does not result in a lower QOS class and relative priority. * * When no quality of service class is specified, the target queue of a newly * created dispatch queue is the default priority global concurrent queue. * * @param label * A string label to attach to the queue. * This parameter is optional and may be NULL. * * @param attr * DISPATCH_QUEUE_SERIAL, DISPATCH_QUEUE_CONCURRENT, or the result of a call to * the function dispatch_queue_attr_make_with_qos_class(). * * @result * The newly created dispatch queue. */@availability(iOS, introduced=4.0)func dispatch_queue_create(label: UnsafePointer<Int8>, attr: dispatch_queue_attr_t!) -> dispatch_queue_t!/*! * @const DISPATCH_CURRENT_QUEUE_LABEL * @discussion Constant to pass to the dispatch_queue_get_label() function to * retrieve the label of the current queue. *//*! * @function dispatch_queue_get_label * * @abstract * Returns the label of the given queue, as specified when the queue was * created, or the empty string if a NULL label was specified. * * Passing DISPATCH_CURRENT_QUEUE_LABEL will return the label of the current * queue. * * @param queue * The queue to query, or DISPATCH_CURRENT_QUEUE_LABEL. * * @result * The label of the queue. */@availability(iOS, introduced=4.0)func dispatch_queue_get_label(queue: dispatch_queue_t!) -> UnsafePointer<Int8>/*! * @function dispatch_queue_get_qos_class * * @abstract * Returns the QOS class and relative priority of the given queue. * * @discussion * If the given queue was created with an attribute value returned from * dispatch_queue_attr_make_with_qos_class(), this function returns the QOS * class and relative priority specified at that time; for any other attribute * value it returns a QOS class of QOS_CLASS_UNSPECIFIED and a relative * priority of 0. * * If the given queue is one of the global queues, this function returns its * assigned QOS class value as documented under dispatch_get_global_queue() and * a relative priority of 0; in the case of the main queue it returns the QOS * value provided by qos_class_main() and a relative priority of 0. * * @param queue * The queue to query. * * @param relative_priority_ptr * A pointer to an int variable to be filled with the relative priority offset * within the QOS class, or NULL. * * @return * A QOS class value: *- QOS_CLASS_USER_INTERACTIVE *- QOS_CLASS_USER_INITIATED *- QOS_CLASS_DEFAULT *- QOS_CLASS_UTILITY *- QOS_CLASS_BACKGROUND *- QOS_CLASS_UNSPECIFIED */@availability(iOS, introduced=8.0)func dispatch_queue_get_qos_class(queue: dispatch_queue_t!, relative_priority_ptr: UnsafeMutablePointer<Int32>) -> dispatch_qos_class_t/*! * @const DISPATCH_TARGET_QUEUE_DEFAULT * @discussion Constant to pass to the dispatch_set_target_queue() and * dispatch_source_create() functions to indicate that the default target queue * for the given object type should be used. *//*! * @function dispatch_set_target_queue * * @abstract * Sets the target queue for the given object. * * @discussion * An object's target queue is responsible for processing the object. * * When no quality of service class and relative priority is specified for a * dispatch queue at the time of creation, a dispatch queue's quality of service * class is inherited from its target queue. The dispatch_get_global_queue() * function may be used to obtain a target queue of a specific quality of * service class, however the use of dispatch_queue_attr_make_with_qos_class() * is recommended instead. * * Blocks submitted to a serial queue whose target queue is another serial * queue will not be invoked concurrently with blocks submitted to the target * queue or to any other queue with that same target queue. * * The result of introducing a cycle into the hierarchy of target queues is * undefined. * * A dispatch source's target queue specifies where its event handler and * cancellation handler blocks will be submitted. * * A dispatch I/O channel's target queue specifies where where its I/O * operations are executed. If the channel's target queue's priority is set to * DISPATCH_QUEUE_PRIORITY_BACKGROUND, then the I/O operations performed by * dispatch_io_read() or dispatch_io_write() on that queue will be * throttled when there is I/O contention. * * For all other dispatch object types, the only function of the target queue * is to determine where an object's finalizer function is invoked. * * @param object * The object to modify. * The result of passing NULL in this parameter is undefined. * * @param queue * The new target queue for the object. The queue is retained, and the * previous target queue, if any, is released. * If queue is DISPATCH_TARGET_QUEUE_DEFAULT, set the object's target queue * to the default target queue for the given object type. */@availability(iOS, introduced=4.0)func dispatch_set_target_queue(object: dispatch_object_t!, queue: dispatch_queue_t!)// DISPATCH_NONNULL1/*! * @function dispatch_main * * @abstract * Execute blocks submitted to the main queue. * * @discussion * This function "parks" the main thread and waits for blocks to be submitted * to the main queue. This function never returns. * * Applications that call NSApplicationMain() or CFRunLoopRun() on the * main thread do not need to call dispatch_main(). */@availability(iOS, introduced=4.0)@noreturn func dispatch_main()/*! * @function dispatch_after * * @abstract * Schedule a block for execution on a given queue at a specified time. * * @discussion * Passing DISPATCH_TIME_NOW as the "when" parameter is supported, but not as * optimal as calling dispatch_async() instead. Passing DISPATCH_TIME_FOREVER * is undefined. * * @param when * A temporal milestone returned by dispatch_time() or dispatch_walltime(). * * @param queue * A queue to which the given block will be submitted at the specified time. * The result of passing NULL in this parameter is undefined. * * @param block * The block of code to execute. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_after(when: dispatch_time_t, queue: dispatch_queue_t!, block: dispatch_block_t!)/*! * @function dispatch_after_f * * @abstract * Schedule a function for execution on a given queue at a specified time. * * @discussion * See dispatch_after() for details. * * @param when * A temporal milestone returned by dispatch_time() or dispatch_walltime(). * * @param queue * A queue to which the given function will be submitted at the specified time. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_after_f(). * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.0)func dispatch_after_f(when: dispatch_time_t, queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: dispatch_function_t)/*! * @functiongroup Dispatch Barrier API * The dispatch barrier API is a mechanism for submitting barrier blocks to a * dispatch queue, analogous to the dispatch_async()/dispatch_sync() API. * It enables the implementation of efficient reader/writer schemes. * Barrier blocks only behave specially when submitted to queues created with * the DISPATCH_QUEUE_CONCURRENT attribute; on such a queue, a barrier block * will not run until all blocks submitted to the queue earlier have completed, * and any blocks submitted to the queue after a barrier block will not run * until the barrier block has completed. * When submitted to a a global queue or to a queue not created with the * DISPATCH_QUEUE_CONCURRENT attribute, barrier blocks behave identically to * blocks submitted with the dispatch_async()/dispatch_sync() API. *//*! * @function dispatch_barrier_async * * @abstract * Submits a barrier block for asynchronous execution on a dispatch queue. * * @discussion * Submits a block to a dispatch queue like dispatch_async(), but marks that * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues). * * See dispatch_async() for details. * * @param queue * The target dispatch queue to which the block is submitted. * The system will hold a reference on the target queue until the block * has finished. * The result of passing NULL in this parameter is undefined. * * @param block * The block to submit to the target dispatch queue. This function performs * Block_copy() and Block_release() on behalf of callers. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.3)func dispatch_barrier_async(queue: dispatch_queue_t!, block: dispatch_block_t!)/*! * @function dispatch_barrier_async_f * * @abstract * Submits a barrier function for asynchronous execution on a dispatch queue. * * @discussion * Submits a function to a dispatch queue like dispatch_async_f(), but marks * that function as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT * queues). * * See dispatch_async_f() for details. * * @param queue * The target dispatch queue to which the function is submitted. * The system will hold a reference on the target queue until the function * has returned. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_barrier_async_f(). * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.3)func dispatch_barrier_async_f(queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: dispatch_function_t)/*! * @function dispatch_barrier_sync * * @abstract * Submits a barrier block for synchronous execution on a dispatch queue. * * @discussion * Submits a block to a dispatch queue like dispatch_sync(), but marks that * block as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues). * * See dispatch_sync() for details. * * @param queue * The target dispatch queue to which the block is submitted. * The result of passing NULL in this parameter is undefined. * * @param block * The block to be invoked on the target dispatch queue. * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.3)func dispatch_barrier_sync(queue: dispatch_queue_t!, block: dispatch_block_t!)/*! * @function dispatch_barrier_sync_f * * @abstract * Submits a barrier function for synchronous execution on a dispatch queue. * * @discussion * Submits a function to a dispatch queue like dispatch_sync_f(), but marks that * fuction as a barrier (relevant only on DISPATCH_QUEUE_CONCURRENT queues). * * See dispatch_sync_f() for details. * * @param queue * The target dispatch queue to which the function is submitted. * The result of passing NULL in this parameter is undefined. * * @param context * The application-defined context parameter to pass to the function. * * @param work * The application-defined function to invoke on the target queue. The first * parameter passed to this function is the context provided to * dispatch_barrier_sync_f(). * The result of passing NULL in this parameter is undefined. */@availability(iOS, introduced=4.3)func dispatch_barrier_sync_f(queue: dispatch_queue_t!, context: UnsafeMutablePointer<Void>, work: dispatch_function_t)/*! * @functiongroup Dispatch queue-specific contexts * This API allows different subsystems to associate context to a shared queue * without risk of collision and to retrieve that context from blocks executing * on that queue or any of its child queues in the target queue hierarchy. *//*! * @function dispatch_queue_set_specific * * @abstract * Associates a subsystem-specific context with a dispatch queue, for a key * unique to the subsystem. * * @discussion * The specified destructor will be invoked with the context on the default * priority global concurrent queue when a new context is set for the same key, * or after all references to the queue have been released. * * @param queue * The dispatch queue to modify. * The result of passing NULL in this parameter is undefined. * * @param key * The key to set the context for, typically a pointer to a static variable * specific to the subsystem. Keys are only compared as pointers and never * dereferenced. Passing a string constant directly is not recommended. * The NULL key is reserved and attemps to set a context for it are ignored. * * @param context * The new subsystem-specific context for the object. This may be NULL. * * @param destructor * The destructor function pointer. This may be NULL and is ignored if context * is NULL. */@availability(iOS, introduced=5.0)func dispatch_queue_set_specific(queue: dispatch_queue_t!, key: UnsafePointer<Void>, context: UnsafeMutablePointer<Void>, destructor: dispatch_function_t)/*! * @function dispatch_queue_get_specific * * @abstract * Returns the subsystem-specific context associated with a dispatch queue, for * a key unique to the subsystem. * * @discussion * Returns the context for the specified key if it has been set on the specified * queue. * * @param queue * The dispatch queue to query. * The result of passing NULL in this parameter is undefined. * * @param key * The key to get the context for, typically a pointer to a static variable * specific to the subsystem. Keys are only compared as pointers and never * dereferenced. Passing a string constant directly is not recommended. * * @result * The context for the specified key or NULL if no context was found. */@availability(iOS, introduced=5.0)func dispatch_queue_get_specific(queue: dispatch_queue_t!, key: UnsafePointer<Void>) -> UnsafeMutablePointer<Void>/*! * @function dispatch_get_specific * * @abstract * Returns the current subsystem-specific context for a key unique to the * subsystem. * * @discussion * When called from a block executing on a queue, returns the context for the * specified key if it has been set on the queue, otherwise returns the result * of dispatch_get_specific() executed on the queue's target queue or NULL * if the current queue is a global concurrent queue. * * @param key * The key to get the context for, typically a pointer to a static variable * specific to the subsystem. Keys are only compared as pointers and never * dereferenced. Passing a string constant directly is not recommended. * * @result * The context for the specified key or NULL if no context was found. */@availability(iOS, introduced=5.0)func dispatch_get_specific(key: UnsafePointer<Void>) -> UnsafeMutablePointer<Void>

0 0
原创粉丝点击