Skip to content

Commit

Permalink
Remove synchronization queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Oct 4, 2024
1 parent 41bbf35 commit 3e0de8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 41 deletions.
17 changes: 5 additions & 12 deletions FirebaseCore/Sources/FIRConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
extern void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel);
extern FIRLoggerLevel FIRGetLoggerLevel(void);

@interface FIRConfiguration ()
@property(nonatomic, readonly) dispatch_queue_t queue;
@end

@implementation FIRConfiguration

+ (instancetype)sharedInstance {
Expand All @@ -37,7 +33,6 @@ + (instancetype)sharedInstance {
- (instancetype)init {
self = [super init];
if (self) {
_queue = dispatch_queue_create("com.firebase.FIRConfiguration", DISPATCH_QUEUE_SERIAL);
_analyticsConfiguration = [FIRAnalyticsConfiguration sharedInstance];
}
return self;
Expand All @@ -46,17 +41,15 @@ - (instancetype)init {
- (void)setLoggerLevel:(FIRLoggerLevel)loggerLevel {
NSAssert(loggerLevel <= FIRLoggerLevelMax && loggerLevel >= FIRLoggerLevelMin,
@"Invalid logger level, %ld", (long)loggerLevel);
dispatch_sync(self.queue, ^{
@synchronized(self) {
FIRSetLoggerLevel(loggerLevel);
});
}
}

- (FIRLoggerLevel)loggerLevel {
__block FIRLoggerLevel level;
dispatch_sync(self.queue, ^{
level = FIRGetLoggerLevel();
});
return level;
@synchronized(self) {
return FIRGetLoggerLevel();
}
}

@end
29 changes: 0 additions & 29 deletions FirebaseCore/Tests/Unit/FIRConfigurationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,4 @@ - (void)testSetAndGet {
}
}

- (void)testSynchronizedAccess {
FIRConfiguration *config = [FIRConfiguration sharedInstance];

__block BOOL raceConditionExists = NO;

// Dispatch to a concurrent queue to simulate concurrent access.
dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_UTILITY, 0);
for (int i = 0; i < 1000000; i++) {
dispatch_async(queue, ^{
// Get the current logging level.
FIRLoggerLevel currentLevel = [config loggerLevel];

// Set a new logging level.
FIRLoggerLevel nextLevel =
(currentLevel + 1 > FIRLoggerLevelMax) ? FIRLoggerLevelMin : currentLevel + 1;
[config setLoggerLevel:nextLevel];

// Confirm that the new logging level is retrieved.
if (nextLevel != [config loggerLevel]) {
raceConditionExists = YES;
}
});
}

dispatch_sync(queue, ^{/* Drain queue before proceeding. */});

XCTAssertEqual(raceConditionExists, NO);
}

@end

0 comments on commit 3e0de8c

Please sign in to comment.