[ASMultiplexImageNode] Avoid deadlock by reading our interface state earlier

This commit is contained in:
Adlai Holler 2016-04-12 17:35:46 -07:00
parent 0022cad000
commit 7128f69678
2 changed files with 8 additions and 4 deletions

View File

@ -456,12 +456,16 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
- (void)_updateProgressImageBlockOnDownloaderIfNeeded
{
// Read our interface state so that we don't lock super while holding our lock.
ASInterfaceState interfaceState = self.interfaceState;
ASDN::MutexLocker l(_downloadIdentifierLock);
if (!_downloaderImplementsSetProgress || _downloadIdentifier == nil) {
return;
}
ASImageDownloaderProgressImage progress = nil;
if (ASInterfaceStateIncludesVisible(self.interfaceState)) {
if (ASInterfaceStateIncludesVisible(interfaceState)) {
__weak __typeof__(self) weakSelf = self;
progress = ^(UIImage * _Nonnull progressImage, id _Nullable downloadIdentifier) {
__typeof__(self) strongSelf = weakSelf;

View File

@ -36,9 +36,9 @@
return result.image;
}
- (void)fetchCachedImageWithURL:(NSURL *)URL
callbackQueue:(dispatch_queue_t)callbackQueue
completion:(void (^)(CGImageRef imageFromCache))completion
- (void)cachedImageWithURL:(NSURL *)URL
callbackQueue:(dispatch_queue_t)callbackQueue
completion:(ASImageCacherCompletion)completion
{
// We do not check the cache here and instead check it in downloadImageWithURL to avoid checking the cache twice.
// If we're targeting the main queue and we're on the main thread, complete immediately.