Mark the `SDAsyncBlockOperation` safe using the lock and correct override method

This commit is contained in:
DreamPiggy 2020-04-30 19:19:55 +08:00
parent 974c3ff4ad
commit f51992cfd6
1 changed files with 39 additions and 19 deletions

View File

@ -35,7 +35,9 @@
} }
- (void)start { - (void)start {
@synchronized (self) {
if (self.isCancelled) { if (self.isCancelled) {
self.finished = YES;
return; return;
} }
@ -46,24 +48,42 @@
if (self.executionBlock) { if (self.executionBlock) {
self.executionBlock(self); self.executionBlock(self);
} else { } else {
[self complete]; self.executing = NO;
self.finished = YES;
}
} }
} }
- (void)cancel { - (void)cancel {
@synchronized (self) {
[super cancel]; [super cancel];
if (self.isExecuting) { if (self.isExecuting) {
[self complete]; self.executing = NO;
self.finished = YES;
}
} }
} }
- (void)complete { - (void)complete {
[self willChangeValueForKey:@"isExecuting"]; @synchronized (self) {
[self willChangeValueForKey:@"isFinished"]; if (self.isExecuting) {
self.executing = NO; self.executing = NO;
self.finished = YES; self.finished = YES;
[self didChangeValueForKey:@"isExecuting"]; }
}
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"];
_finished = finished;
[self didChangeValueForKey:@"isFinished"]; [self didChangeValueForKey:@"isFinished"];
} }
- (void)setExecuting:(BOOL)executing {
[self willChangeValueForKey:@"isExecuting"];
_executing = executing;
[self didChangeValueForKey:@"isExecuting"];
}
@end @end