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:
parent
ad592765cb
commit
6b8075a2e1
|
@ -29,6 +29,9 @@ typedef void(^SDInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nu
|
||||||
*/
|
*/
|
||||||
- (void)cancel;
|
- (void)cancel;
|
||||||
|
|
||||||
|
/// Whether the operation has been cancelled.
|
||||||
|
@property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The cache operation from the image cache query
|
The cache operation from the image cache query
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -803,12 +803,20 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
|
|
||||||
@implementation SDWebImageCombinedOperation
|
@implementation SDWebImageCombinedOperation
|
||||||
|
|
||||||
- (void)cancel {
|
- (BOOL)isCancelled {
|
||||||
|
// Need recursive lock (user's cancel block may check isCancelled), do not use SD_LOCK
|
||||||
@synchronized (self) {
|
@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;
|
return;
|
||||||
}
|
}
|
||||||
self.cancelled = YES;
|
_cancelled = YES;
|
||||||
if (self.cacheOperation) {
|
if (self.cacheOperation) {
|
||||||
[self.cacheOperation cancel];
|
[self.cacheOperation cancel];
|
||||||
self.cacheOperation = nil;
|
self.cacheOperation = nil;
|
||||||
|
|
Loading…
Reference in New Issue