On 7 Dec, 2013, at 12:46 am, Graham Cox <graham....@bigpond.com> wrote:

> 
>                               
>                                       @synchronized( self )
>                                       {
>                                               CGContextDrawImage( ctx, 
> tileRect, tileImage );
>                                       }
>                                       CGImageRelease( tileImage );
>                                       
>                                       free( bitsPtr );
>                               }];
>                               
>                               [mDrawingQueue addOperation:op];
> #else
>                               [self drawTile:tileRect inContext:ctx];
> #endif
>               
>                       }
>               }
>       }
>       
> #if DRAW_THREADED
>       [mDrawingQueue waitUntilAllOperationsAreFinished];
> #endif
>       

You could also, instead of synchronizing the CGContextDrawImage(), which may 
make your threads wait for each other for some infinitessimal time, use

dispatch_async( dispatch_get_main_queue(), {
        CGContextDrawImage( ctx, tileRect, tileImage );
        CGImageRelease( tileImage );
        free( bitsPtr );
}

which serializes them. And I doubt it would make a sod of difference. 

For completeness, if you wanted a dispatch queue as opposed to NSOperationQueue 
based approach, setting up a dispatch queue, concurrent one, and using 
dispatch_apply() with iterations = tx * ty would do that, and wait for 
completion, so you don't need the waitUntilAllOperationsAreFinished.  But 
that's just preference, I use dispatch queues when I can most of the time. 

And reminded of the comment about how hard block syntax can be to remember, I 
didn't make this page, I'm not a fan of the name, but it's awfully useful and I 
keep it bookmarked,  I tinyURLed it to avoid tripping up swear checkers, 
http://tinyurl.com/m6lukyg. 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to