Fix the thread safe issue with Downloader and DownloaderOperation during cancel
This commit is contained in:
parent
bc9b488bf3
commit
9dae0e7b96
|
@ -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