rs/SDWebImage — pull request #781 by bpoplauschi (2014-06-24 21:04:17+00:00)
Title: Fixed deadlocks, completion blocks async, race condition on cancel

#### Fixed issues #625 #507 aka deadlocks (replaces #509)
- In order to fix the deadlock, reviewed the `[SDImageCache diskImageExistsWithKey:]` method. Based on the Apple doc for `NSFileManager`, using the `defaultManager` without the dispatch on the `ioQueue` to avoid the deadlocks. This instance is thread safe. Also created an async variant of this method `[SDImageCache diskImageExistsWithKey:completion:]`
For consistency, added async methods in `SDWebImageManager` `cachedImageExistsForURL:completion:` and `diskImageExistsForURL:completion:`
- More fixes against deadlocks. `dispatch_sync` on a serial queue is an [anti pattern](http://www.raywenderlich.com/60749/grand-central-dispatch-in-depth-part-1), as it can lead to deadlocks. I replaced all the `dispatch_main_sync_safe` with `dispatch_main_async_safe`, based on the fact that the completion blocks are not returning anything, so we don't need to wait for them to finish.
- The biggest change (architectural) is that the completion block will no longer be executed inside the operation. But that is not an issue, as `NSOperation` does the same (completion block gets called after operation `isFinished`).

#### Fixed race condition In SDWebImageManager (replaces #699)
- In SDWebImageManager if one operation is cancelled, the completion block must not be called, otherwise it might race with a newer completion for the same object