Fix the thread safe issue with Downloader and DownloaderOperation during cancel #2903
This commit is contained in:
parent
0cd36c6338
commit
853325139f
|
@ -354,7 +354,12 @@
|
|||
NSOperation<SDWebImageDownloaderOperationInterface> *returnOperation = nil;
|
||||
for (NSOperation<SDWebImageDownloaderOperationInterface> *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