Merge pull request #2048 from dreampiggy/fix_cancelBlock_multi_thread_issue
Fix #1941 by placing a lock to avoid multi-thread issue for SDWebImageCombinedOperation cancelBlock
This commit is contained in:
commit
b12ef07e5e
|
@ -228,11 +228,14 @@
|
|||
[self safelyRemoveOperationFromRunning:strongOperation];
|
||||
}
|
||||
}];
|
||||
@synchronized(operation) {
|
||||
// Need same lock to ensure cancelBlock called because cancel method can be called in different queue
|
||||
operation.cancelBlock = ^{
|
||||
[self.imageDownloader cancel:subOperationToken];
|
||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||
[self safelyRemoveOperationFromRunning:strongOperation];
|
||||
};
|
||||
}
|
||||
} else if (cachedImage) {
|
||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||
[self callCompletionBlockForOperation:strongOperation completion:completedBlock image:cachedImage data:cachedData error:nil cacheType:cacheType finished:YES url:url];
|
||||
|
@ -319,6 +322,7 @@
|
|||
}
|
||||
|
||||
- (void)cancel {
|
||||
@synchronized(self) {
|
||||
self.cancelled = YES;
|
||||
if (self.cacheOperation) {
|
||||
[self.cacheOperation cancel];
|
||||
|
@ -326,11 +330,8 @@
|
|||
}
|
||||
if (self.cancelBlock) {
|
||||
self.cancelBlock();
|
||||
|
||||
// TODO: this is a temporary fix to #809.
|
||||
// Until we can figure the exact cause of the crash, going with the ivar instead of the setter
|
||||
// self.cancelBlock = nil;
|
||||
_cancelBlock = nil;
|
||||
self.cancelBlock = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue