Authored by 刘金林

fix deadlock issue for dev_t627

@@ -132,6 +132,18 @@ static NSString *const kParamKeyType = @"type"; @@ -132,6 +132,18 @@ static NSString *const kParamKeyType = @"type";
132 [performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT]; 132 [performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
133 [performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN]; 133 [performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
134 134
  135 + //临时应对 dev_t627
  136 + __block NSString *pageChains = @"";
  137 + if (type == YHPT_NETWORK) {
  138 + if ([NSThread isMainThread]) {
  139 + pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
  140 + } else {
  141 + dispatch_sync(dispatch_get_main_queue(), ^{
  142 + pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
  143 + });
  144 + }
  145 + }
  146 +
135 dispatch_async(self.queue, ^{ 147 dispatch_async(self.queue, ^{
136 NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.appInfo] mutableCopy]; 148 NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.appInfo] mutableCopy];
137 [eventDic addEntriesFromDictionary:performanceDic]; 149 [eventDic addEntriesFromDictionary:performanceDic];
@@ -140,7 +152,6 @@ static NSString *const kParamKeyType = @"type"; @@ -140,7 +152,6 @@ static NSString *const kParamKeyType = @"type";
140 case YHPT_NETWORK: 152 case YHPT_NETWORK:
141 { 153 {
142 NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data]; 154 NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data];
143 - NSString *pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";  
144 [appendDict setValue:pageChains forKey:YOHOAppReportKeyJsonKeyPageChain]; 155 [appendDict setValue:pageChains forKey:YOHOAppReportKeyJsonKeyPageChain];
145 [self checkBaiduStatusWithEventData:eventDic customData:appendDict]; 156 [self checkBaiduStatusWithEventData:eventDic customData:appendDict];
146 } 157 }
@@ -46,7 +46,7 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) { @@ -46,7 +46,7 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
46 @property (nonatomic, strong) NSMutableArray *tabViewControllerArray; 46 @property (nonatomic, strong) NSMutableArray *tabViewControllerArray;
47 /**页面调用链*/ 47 /**页面调用链*/
48 @property (nonatomic, strong) NSMutableArray *pageChains; 48 @property (nonatomic, strong) NSMutableArray *pageChains;
49 -@property (nonatomic, strong) NSLock *lock; 49 +//@property (nonatomic, strong) NSLock *lock;
50 @end 50 @end
51 51
52 52
@@ -68,8 +68,8 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) { @@ -68,8 +68,8 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
68 self.serialQueue = dispatch_queue_create([kYHEventReportQueue UTF8String], DISPATCH_QUEUE_SERIAL); 68 self.serialQueue = dispatch_queue_create([kYHEventReportQueue UTF8String], DISPATCH_QUEUE_SERIAL);
69 self.timedEvents = [NSMutableDictionary dictionary]; 69 self.timedEvents = [NSMutableDictionary dictionary];
70 self.pageChains = [NSMutableArray array]; 70 self.pageChains = [NSMutableArray array];
71 - self.lock = [[NSLock alloc] init];  
72 - self.lock.name = @"com.yoho.buy.EventCollector"; 71 +// self.lock = [[NSLock alloc] init];
  72 +// self.lock.name = @"com.yoho.buy.EventCollector";
73 NSArray *tabAry= @[]; 73 NSArray *tabAry= @[];
74 self.tabViewControllerArray = [NSMutableArray arrayWithArray:tabAry]; 74 self.tabViewControllerArray = [NSMutableArray arrayWithArray:tabAry];
75 75
@@ -645,26 +645,27 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) { @@ -645,26 +645,27 @@ NS_INLINE NSString *YH_Objectkey(id anyObject) {
645 if (!viewController) { 645 if (!viewController) {
646 return; 646 return;
647 } 647 }
648 -  
649 - [self.lock lock]; 648 + NSParameterAssert(NSThread.isMainThread);
  649 +// [self.lock lock];
650 650
651 if (self.pageChains.count > 10) { 651 if (self.pageChains.count > 10) {
652 [self.pageChains removeObjectAtIndex:0]; 652 [self.pageChains removeObjectAtIndex:0];
653 } 653 }
654 [self.pageChains addObject:[NSString stringWithFormat:@"%@",[viewController class]]]; 654 [self.pageChains addObject:[NSString stringWithFormat:@"%@",[viewController class]]];
655 655
656 - [self.lock unlock]; 656 +// [self.lock unlock];
657 } 657 }
658 658
659 - (NSString *)pageChainStr 659 - (NSString *)pageChainStr
660 { 660 {
661 - [self.lock lock]; 661 + NSParameterAssert(NSThread.isMainThread);
  662 +// [self.lock lock];
662 if (!self.pageChains || self.pageChains.count == 0) { 663 if (!self.pageChains || self.pageChains.count == 0) {
663 return @""; 664 return @"";
664 } 665 }
665 666
666 NSString *resultChain = [[[self.pageChains reverseObjectEnumerator] allObjects] componentsJoinedByString:@","]; 667 NSString *resultChain = [[[self.pageChains reverseObjectEnumerator] allObjects] componentsJoinedByString:@","];
667 - [self.lock unlock]; 668 +// [self.lock unlock];
668 669
669 return resultChain; 670 return resultChain;
670 } 671 }