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:
commit
247cbcfd97
|
@ -334,7 +334,7 @@ BOOL SDWebImageDownloaderOperationGetCompleted(id<SDWebImageDownloaderOperation>
|
|||
[self didChangeValueForKey:@"isExecuting"];
|
||||
}
|
||||
|
||||
- (BOOL)isConcurrent {
|
||||
- (BOOL)isAsynchronous {
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)isConcurrent {
|
||||
- (BOOL)isAsynchronous {
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue