use @syncrhonized (self) in the whole checkDone method, no longer allows something that add new handlers during checkDone

This commit is contained in:
马遥 2023-07-28 14:56:28 +08:00
parent 1ee0dbacea
commit 2d73e96fdf
1 changed files with 10 additions and 11 deletions

View File

@ -343,18 +343,17 @@
// if all tokens have been processed call [self done]. // if all tokens have been processed call [self done].
- (void)checkDoneWithImageData:(NSData *)imageData - (void)checkDoneWithImageData:(NSData *)imageData
finishedTokens:(NSArray<SDWebImageDownloaderOperationToken *> *)finishedTokens { finishedTokens:(NSArray<SDWebImageDownloaderOperationToken *> *)finishedTokens {
NSMutableArray<SDWebImageDownloaderOperationToken *> *tokens;
@synchronized (self) { @synchronized (self) {
tokens = [self.callbackTokens mutableCopy]; NSMutableArray<SDWebImageDownloaderOperationToken *> *tokens = [self.callbackTokens mutableCopy];
} [finishedTokens enumerateObjectsUsingBlock:^(SDWebImageDownloaderOperationToken * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[finishedTokens enumerateObjectsUsingBlock:^(SDWebImageDownloaderOperationToken * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [tokens removeObjectIdenticalTo:obj];
[tokens removeObjectIdenticalTo:obj]; }];
}]; if (tokens.count == 0) {
if (tokens.count == 0) { [self done];
[self done]; } else {
} else { // If there are new tokens added during the decoding operation, the decoding operation is supplemented with these new tokens.
// If there are new tokens added during the decoding operation, the decoding operation is supplemented with these new tokens. [self startCoderOperationWithImageData:imageData pendingTokens:tokens finishedTokens:finishedTokens];
[self startCoderOperationWithImageData:imageData pendingTokens:tokens finishedTokens:finishedTokens]; }
} }
} }