Skip to content

Commit bc03222

Browse files
committed
Corrections based on comments regarding dead lock and nitpick
Capture strong self during async observer registration
1 parent 5f1bc14 commit bc03222

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

FirebasePerformance/Sources/AppActivity/FPRTraceBackgroundActivityTracker.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ - (instancetype)init {
3737
} else {
3838
_traceBackgroundState = FPRTraceStateForegroundOnly;
3939
}
40-
if ([NSThread isMainThread]) {
41-
[self registerNotificationObservers];
42-
} else {
43-
dispatch_sync(dispatch_get_main_queue(), ^{
44-
[self registerNotificationObservers];
45-
});
46-
}
40+
__strong typeof(self) strongSelf = self;
41+
dispatch_async(dispatch_get_main_queue(), ^{
42+
[strongSelf registerNotificationObservers];
43+
});
4744
}
4845
return self;
4946
}

FirebasePerformance/Tests/Unit/FPRTraceBackgroundActivityTrackerTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ - (void)testObservers_synchronousRegistrationAddsObserver {
8181
object:[UIApplication sharedApplication]]);
8282
}
8383

84-
/** Tests rapid creation and deallocation to verify race condition fix. */
84+
/** Tests rapid creation and deallocation to verify race condition. */
8585
- (void)testRapidCreationAndDeallocation_noRaceCondition {
8686
for (int i = 0; i < 100; i++) {
8787
@autoreleasepool {

0 commit comments

Comments
 (0)