Merge pull request #3479 from dreampiggy/bugfix/fix_async_block_operation_race

Try to fix the SDAsyncBlockOperation's race condition
This commit is contained in:
DreamPiggy 2023-02-06 21:49:43 +08:00 committed by GitHub
commit 247cbcfd97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

View File

@ -334,7 +334,7 @@ BOOL SDWebImageDownloaderOperationGetCompleted(id<SDWebImageDownloaderOperation>
[self didChangeValueForKey:@"isExecuting"];
}
- (BOOL)isConcurrent {
- (BOOL)isAsynchronous {
return YES;
}

View File

@ -7,6 +7,7 @@
*/
#import "SDAsyncBlockOperation.h"
#import "SDInternalMacros.h"
@interface SDAsyncBlockOperation ()
@ -38,16 +39,17 @@
self.finished = YES;
return;
}
self.finished = NO;
self.executing = YES;
if (self.executionBlock) {
self.executionBlock(self);
} else {
self.executing = NO;
self.finished = YES;
}
}
SDAsyncBlock executionBlock = self.executionBlock;
if (executionBlock) {
@weakify(self);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
@strongify(self);
if (!self) return;
executionBlock(self);
});
}
}
@ -69,7 +71,7 @@
self.executing = NO;
}
}
}
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"];
@ -83,7 +85,7 @@
[self didChangeValueForKey:@"isExecuting"];
}
- (BOOL)isConcurrent {
- (BOOL)isAsynchronous {
return YES;
}

View File

@ -36,7 +36,7 @@
}
}
- (BOOL)isConcurrent {
- (BOOL)isAsynchronous {
return YES;
}