From e345aa8879a8dd005e4591ad1188113c951f1d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 30 Mar 2023 10:44:23 +0800 Subject: [PATCH] iOS: fix crash when on concurrent op --- .../Performance/DoricPerformanceProfile.m | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/Performance/DoricPerformanceProfile.m b/doric-iOS/Pod/Classes/Performance/DoricPerformanceProfile.m index 1c877133..43b2e3b1 100644 --- a/doric-iOS/Pod/Classes/Performance/DoricPerformanceProfile.m +++ b/doric-iOS/Pod/Classes/Performance/DoricPerformanceProfile.m @@ -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]];