Replace @synchronized lock with dispatch_semaphore lock for SDWebImageCombinedOperation
This commit is contained in:
parent
7dc38751e9
commit
09020fac87
|
@ -347,20 +347,34 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface SDWebImageCombinedOperation ()
|
||||||
|
|
||||||
|
@property (strong, nonatomic, nonnull) dispatch_semaphore_t cancelLock; // a lock to make the `cancel` method thread-safe
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageCombinedOperation
|
@implementation SDWebImageCombinedOperation
|
||||||
|
|
||||||
- (void)cancel {
|
- (instancetype)init {
|
||||||
@synchronized(self) {
|
self = [super init];
|
||||||
self.cancelled = YES;
|
if (self) {
|
||||||
if (self.cacheOperation) {
|
_cancelLock = dispatch_semaphore_create(1);
|
||||||
[self.cacheOperation cancel];
|
|
||||||
self.cacheOperation = nil;
|
|
||||||
}
|
|
||||||
if (self.downloadToken) {
|
|
||||||
[self.manager.imageDownloader cancel:self.downloadToken];
|
|
||||||
}
|
|
||||||
[self.manager safelyRemoveOperationFromRunning:self];
|
|
||||||
}
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancel {
|
||||||
|
LOCK(self.cancelLock);
|
||||||
|
self.cancelled = YES;
|
||||||
|
if (self.cacheOperation) {
|
||||||
|
[self.cacheOperation cancel];
|
||||||
|
self.cacheOperation = nil;
|
||||||
|
}
|
||||||
|
if (self.downloadToken) {
|
||||||
|
[self.manager.imageDownloader cancel:self.downloadToken];
|
||||||
|
}
|
||||||
|
[self.manager safelyRemoveOperationFromRunning:self];
|
||||||
|
UNLOCK(self.cancelLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue