Authored by 刘金林

fix deadlock issue for dev_t627

... ... @@ -132,6 +132,18 @@ static NSString *const kParamKeyType = @"type";
[performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
//临时应对 dev_t627
__block NSString *pageChains = @"";
if (type == YHPT_NETWORK) {
if ([NSThread isMainThread]) {
pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
});
}
}
dispatch_async(self.queue, ^{
NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.appInfo] mutableCopy];
[eventDic addEntriesFromDictionary:performanceDic];
... ... @@ -140,7 +152,6 @@ static NSString *const kParamKeyType = @"type";
case YHPT_NETWORK:
{
NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data];
NSString *pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
[appendDict setValue:pageChains forKey:YOHOAppReportKeyJsonKeyPageChain];
[self checkBaiduStatusWithEventData:eventDic customData:appendDict];
}
... ...
... ... @@ -46,7 +46,7 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
@property (nonatomic, strong) NSMutableArray *tabViewControllerArray;
/**页面调用链*/
@property (nonatomic, strong) NSMutableArray *pageChains;
@property (nonatomic, strong) NSLock *lock;
//@property (nonatomic, strong) NSLock *lock;
@end
... ... @@ -68,8 +68,8 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
self.serialQueue = dispatch_queue_create([kYHEventReportQueue UTF8String], DISPATCH_QUEUE_SERIAL);
self.timedEvents = [NSMutableDictionary dictionary];
self.pageChains = [NSMutableArray array];
self.lock = [[NSLock alloc] init];
self.lock.name = @"com.yoho.buy.EventCollector";
// self.lock = [[NSLock alloc] init];
// self.lock.name = @"com.yoho.buy.EventCollector";
NSArray *tabAry= @[];
self.tabViewControllerArray = [NSMutableArray arrayWithArray:tabAry];
... ... @@ -645,26 +645,27 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
if (!viewController) {
return;
}
[self.lock lock];
NSParameterAssert(NSThread.isMainThread);
// [self.lock lock];
if (self.pageChains.count > 10) {
[self.pageChains removeObjectAtIndex:0];
}
[self.pageChains addObject:[NSString stringWithFormat:@"%@",[viewController class]]];
[self.lock unlock];
// [self.lock unlock];
}
- (NSString *)pageChainStr
{
[self.lock lock];
NSParameterAssert(NSThread.isMainThread);
// [self.lock lock];
if (!self.pageChains || self.pageChains.count == 0) {
return @"";
}
NSString *resultChain = [[[self.pageChains reverseObjectEnumerator] allObjects] componentsJoinedByString:@","];
[self.lock unlock];
// [self.lock unlock];
return resultChain;
}
... ...