iOS: fix crash when on concurrent op

This commit is contained in:
王劲鹏 2023-03-30 10:44:23 +08:00 committed by osborn
parent 9a6ae9b6ef
commit e345aa8879

View File

@ -44,11 +44,23 @@ - (instancetype)initWithName:(NSString *)name {
}
- (void)addAnchorHook:(id)hook {
[self.hooks addObject:hook];
__weak typeof(self) _self = self;
dispatch_async(self.anchorQueue, ^{
__strong typeof(_self) self = _self;
if (!self) return;
[self.hooks addObject:hook];
});
}
- (void)removeAnchorHook:(id)hook {
[self.hooks removeObject:hook];
__weak typeof(self) _self = self;
dispatch_async(self.anchorQueue, ^{
__strong typeof(_self) self = _self;
if (!self) return;
[self.hooks removeObject:hook];
});
}
- (void)enable:(bool)enable {
@ -95,7 +107,11 @@ - (void)print:(NSString *)anchorName {
if (!self.enable) {
return;
}
__weak typeof(self) _self = self;
dispatch_async(self.anchorQueue, ^{
__strong typeof(_self) self = _self;
if (!self) return;
NSNumber *prepare = self.anchorMap[[self getPrepareAnchor:anchorName]];
NSNumber *start = self.anchorMap[[self getStartAnchor:anchorName]];
NSNumber *end = self.anchorMap[[self getEndAnchor:anchorName]];