dispatch_block_create_with_qos_class

Function dispatch_block_create_with_qos_class 

Source
pub unsafe extern "C" fn dispatch_block_create_with_qos_class(
    flags: dispatch_block_flags_t,
    qos_class: DispatchQoS,
    relative_priority: c_int,
    block: dispatch_block_t,
) -> dispatch_block_t
Expand description

Create a new dispatch block object on the heap from an existing block and the given flags, and assign it the specified QOS class and relative priority.

The provided block is Block_copy’ed to the heap and retained by the newly created dispatch block object.

The returned dispatch block object is intended to be submitted to a dispatch queue with dispatch_async() and related functions, but may also be invoked directly. Both operations can be performed an arbitrary number of times but only the first completed execution of a dispatch block object can be waited on with dispatch_block_wait() or observed with dispatch_block_notify().

If invoked directly, the returned dispatch block object will be executed with the assigned QOS class as long as that does not result in a lower QOS class than what is current on the calling thread.

If the returned dispatch block object is submitted to a dispatch queue, the QOS class it will be executed with depends on the QOS class assigned to the block, the QOS class assigned to the queue and which of the following flags was specified or defaulted to:

  • DISPATCH_BLOCK_INHERIT_QOS_CLASS: default for asynchronous execution
  • DISPATCH_BLOCK_ENFORCE_QOS_CLASS: default for synchronous execution See description of dispatch_block_flags_t for details.

If the returned dispatch block object is submitted directly to a serial queue and is configured to execute with a specific QOS class, the system will make a best effort to apply the necessary QOS overrides to ensure that blocks submitted earlier to the serial queue are executed at that same QOS class or higher.

Parameter flags: Configuration flags for the new block object. Passing a value that is not a bitwise OR of flags from dispatch_block_flags_t results in NULL being returned.

Parameter qos_class: A QOS class value:

  • QOS_CLASS_USER_INTERACTIVE
  • QOS_CLASS_USER_INITIATED
  • QOS_CLASS_DEFAULT
  • QOS_CLASS_UTILITY
  • QOS_CLASS_BACKGROUND
  • QOS_CLASS_UNSPECIFIED Passing QOS_CLASS_UNSPECIFIED is equivalent to specifying the DISPATCH_BLOCK_NO_QOS_CLASS flag. Passing any other value results in NULL being returned.

Parameter 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.

Parameter block: The block to create the dispatch block object from.

Returns: The newly created dispatch block object, or NULL. When not building with Objective-C ARC, must be released with a -[release] message or the Block_release() function.