Merge pull request #2903 from dreampiggy/fix_thread_safe_datatask
Fix the thread safe issue with Downloader and DownloaderOperation during cancel
This commit is contained in:
commit
421ed8fa8a
|
@ -9,7 +9,6 @@
|
|||
#import "SDWebImageDefine.h"
|
||||
#import "UIImage+Metadata.h"
|
||||
#import "NSImage+Compatibility.h"
|
||||
#import "UIImage+ExtendedCacheData.h"
|
||||
#import "SDAssociatedObject.h"
|
||||
|
||||
#pragma mark - Image scale
|
||||
|
|
|
@ -403,7 +403,12 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
NSOperation<SDWebImageDownloaderOperation> *returnOperation = nil;
|
||||
for (NSOperation<SDWebImageDownloaderOperation> *operation in self.downloadQueue.operations) {
|
||||
if ([operation respondsToSelector:@selector(dataTask)]) {
|
||||
if (operation.dataTask.taskIdentifier == task.taskIdentifier) {
|
||||
// So we lock the operation here, and in `SDWebImageDownloaderOperation`, we use `@synchonzied (self)`, to ensure the thread safe between these two classes.
|
||||
NSURLSessionTask *operationTask;
|
||||
@synchronized (operation) {
|
||||
operationTask = operation.dataTask;
|
||||
}
|
||||
if (operationTask.taskIdentifier == task.taskIdentifier) {
|
||||
returnOperation = operation;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue