|
38 | 38 | /// The storage sub-directory that the Remote Config database resides in. |
39 | 39 | static NSString *const RCNRemoteConfigStorageSubDirectory = @"Google/RemoteConfig"; |
40 | 40 |
|
| 41 | +/// Introduce a dedicated serial queue for gIsNewDatabase access. |
| 42 | +static dispatch_queue_t gIsNewDatabaseQueue; |
| 43 | + |
41 | 44 | /// Remote Config database path for deprecated V0 version. |
42 | 45 | static NSString *RemoteConfigPathForOldDatabaseV0(void) { |
43 | 46 | NSArray *dirPaths = |
@@ -82,7 +85,9 @@ static BOOL RemoteConfigCreateFilePathIfNotExist(NSString *filePath) { |
82 | 85 | } |
83 | 86 | NSFileManager *fileManager = [NSFileManager defaultManager]; |
84 | 87 | if (![fileManager fileExistsAtPath:filePath]) { |
85 | | - gIsNewDatabase = YES; |
| 88 | + dispatch_sync(gIsNewDatabaseQueue, ^{ |
| 89 | + gIsNewDatabase = YES; |
| 90 | + }); |
86 | 91 | NSError *error; |
87 | 92 | [fileManager createDirectoryAtPath:[filePath stringByDeletingLastPathComponent] |
88 | 93 | withIntermediateDirectories:YES |
@@ -119,6 +124,8 @@ + (instancetype)sharedInstance { |
119 | 124 | static dispatch_once_t onceToken; |
120 | 125 | static RCNConfigDBManager *sharedInstance; |
121 | 126 | dispatch_once(&onceToken, ^{ |
| 127 | + gIsNewDatabaseQueue = dispatch_queue_create("com.google.FirebaseRemoteConfig.gIsNewDatabase", |
| 128 | + DISPATCH_QUEUE_SERIAL); |
122 | 129 | sharedInstance = [[RCNConfigDBManager alloc] init]; |
123 | 130 | }); |
124 | 131 | return sharedInstance; |
@@ -1219,7 +1226,19 @@ - (BOOL)logErrorWithSQL:(const char *)SQL |
1219 | 1226 | } |
1220 | 1227 |
|
1221 | 1228 | - (BOOL)isNewDatabase { |
1222 | | - return gIsNewDatabase; |
| 1229 | + __block BOOL isNew; |
| 1230 | + dispatch_sync(gIsNewDatabaseQueue, ^{ |
| 1231 | + isNew = gIsNewDatabase; |
| 1232 | + }); |
| 1233 | + return isNew; |
| 1234 | +} |
| 1235 | + |
| 1236 | +- (void)waitForDatabaseOperationQueue { |
| 1237 | + // This dispatch_sync call ensures that all blocks queued before it on _databaseOperationQueue |
| 1238 | + // (including the createOrOpenDatabase setup block) execute and complete before this method |
| 1239 | + // returns. |
| 1240 | + dispatch_sync(_databaseOperationQueue, ^{ |
| 1241 | + }); |
1223 | 1242 | } |
1224 | 1243 |
|
1225 | 1244 | @end |
0 commit comments