1

My problem is very simple

+ (void) SpecialDispatchSyncTo:(dispatch_queue_t)iQueue DispatchBlock:(dispatch_block_t)block
{
    if (dispatch_get_current_queue() == iQueue) 
    {
        block();
    } 
    else 
    {
        dispatch_sync(iQueue, block);
    }  
}

I use this bit of code to increase performance of some of my apps.

It's use is fairly obvious from the code - when I am dispatching to a specific queue it directly invokes the block instead of going through the dispatcher.

now my problem is with the ios 6 deprecation of the get_current_queue function, any ideas how to retain this functionality with ios 6 + ?

edit:

This isn't a duplicate of Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6

To better explain myself, and unlike the linked duplicate looking question... I have no desire to run the block on the "caller method's queue"... rather I want to optimise the dispatch(I'm overriding the normal dispatch methods in essence) by not dispatching to a queue IF I'm already on that queue.

For example, consider the scenario where function a (which is a UI event callback) and function b (background low priority queue) both call function c, which among other things needs to dispatch a block to the "background low priority queue"... a pointless dispatch if I'm in the flow of function b -> function c... hence my optimisation. This improves performance I guarantee it, and I'll implement my own "get current queue" if needed by enhancing the runloop object but I'm not sure I want to go down that path and wanted to see if someone has ideas how to do it.

Community
  • 1
  • 1
Miki Bergin
  • 161
  • 11

0 Answers0