Using the same synchornized to guard _cancelled status, which need recursive lock

DO NOT USE SD_LOCK (os_unfair_lock), which not support recursive
This commit is contained in:
DreamPiggy 2022-09-19 17:33:04 +08:00
parent ad592765cb
commit 6b8075a2e1
2 changed files with 13 additions and 2 deletions

View File

@ -29,6 +29,9 @@ typedef void(^SDInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nu
*/
- (void)cancel;
/// Whether the operation has been cancelled.
@property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelled;
/**
The cache operation from the image cache query
*/

View File

@ -803,12 +803,20 @@ static id<SDImageLoader> _defaultImageLoader;
@implementation SDWebImageCombinedOperation
- (void)cancel {
- (BOOL)isCancelled {
// Need recursive lock (user's cancel block may check isCancelled), do not use SD_LOCK
@synchronized (self) {
if (self.isCancelled) {
return _cancelled;
}
}
- (void)cancel {
// Need recursive lock (user's cancel block may check isCancelled), do not use SD_LOCK
@synchronized(self) {
if (_cancelled) {
return;
}
self.cancelled = YES;
_cancelled = YES;
if (self.cacheOperation) {
[self.cacheOperation cancel];
self.cacheOperation = nil;