Revert "Synchronise getter and setter of the cancelled property of the SDWebImageCombinedOperation in order to eliminate data race."

This reverts commit 5a18c84529.
This commit is contained in:
DreamPiggy 2022-09-19 17:28:38 +08:00
parent 122c3d7ca5
commit ad592765cb
1 changed files with 15 additions and 34 deletions

View File

@ -17,9 +17,7 @@
static id<SDImageCache> _defaultImageCache; static id<SDImageCache> _defaultImageCache;
static id<SDImageLoader> _defaultImageLoader; static id<SDImageLoader> _defaultImageLoader;
@interface SDWebImageCombinedOperation () { @interface SDWebImageCombinedOperation ()
SD_LOCK_DECLARE(_cancelledLock); // a lock to keep the access to `cancelled` thread-safe
}
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled; @property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
@property (strong, nonatomic, readwrite, nullable) id<SDWebImageOperation> loaderOperation; @property (strong, nonatomic, readwrite, nullable) id<SDWebImageOperation> loaderOperation;
@ -805,39 +803,22 @@ static id<SDImageLoader> _defaultImageLoader;
@implementation SDWebImageCombinedOperation @implementation SDWebImageCombinedOperation
- (instancetype)init {
if (self = [super init]) {
SD_LOCK_INIT(_cancelledLock);
}
return self;
}
- (BOOL)isCancelled {
BOOL isCancelled = NO;
SD_LOCK(_cancelledLock);
isCancelled = _cancelled;
SD_UNLOCK(_cancelledLock);
return isCancelled;
}
- (void)cancel { - (void)cancel {
SD_LOCK(_cancelledLock); @synchronized(self) {
if (_cancelled) { if (self.isCancelled) {
SD_UNLOCK(_cancelledLock); return;
return; }
self.cancelled = YES;
if (self.cacheOperation) {
[self.cacheOperation cancel];
self.cacheOperation = nil;
}
if (self.loaderOperation) {
[self.loaderOperation cancel];
self.loaderOperation = nil;
}
[self.manager safelyRemoveOperationFromRunning:self];
} }
_cancelled = YES;
if (self.cacheOperation) {
[self.cacheOperation cancel];
self.cacheOperation = nil;
}
if (self.loaderOperation) {
[self.loaderOperation cancel];
self.loaderOperation = nil;
}
[self.manager safelyRemoveOperationFromRunning:self];
SD_UNLOCK(_cancelledLock);
} }
@end @end