Fix Modules concurrent access

Reviewed By: fkgozali

Differential Revision: D8379392

fbshipit-source-id: 72495950ea5fcf37f5b1cc3413666879dfc81e5c
This commit is contained in:
Dmitry Zakharov 2018-06-18 07:37:23 -07:00 committed by Facebook Github Bot
parent a130239257
commit 2f53573d4f
1 changed files with 10 additions and 2 deletions

View File

@ -34,9 +34,14 @@ NSString *const RCTBridgeDidDownloadScriptNotificationSourceKey = @"source";
NSString *const RCTBridgeDidDownloadScriptNotificationBridgeDescriptionKey = @"bridgeDescription";
static NSMutableArray<Class> *RCTModuleClasses;
static dispatch_queue_t RCTModuleClassesSyncQueue;
NSArray<Class> *RCTGetModuleClasses(void)
{
return RCTModuleClasses;
__block NSArray<Class> *result;
dispatch_sync(RCTModuleClassesSyncQueue, ^{
result = [RCTModuleClasses copy];
});
return result;
}
void RCTFBQuickPerformanceLoggerConfigureHooks(__unused JSGlobalContextRef ctx) { }
@ -51,6 +56,7 @@ void RCTRegisterModule(Class moduleClass)
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
RCTModuleClasses = [NSMutableArray new];
RCTModuleClassesSyncQueue = dispatch_queue_create("com.facebook.react.ModuleClassesSyncQueue", DISPATCH_QUEUE_CONCURRENT);
});
RCTAssert([moduleClass conformsToProtocol:@protocol(RCTBridgeModule)],
@ -58,7 +64,9 @@ void RCTRegisterModule(Class moduleClass)
moduleClass);
// Register module
[RCTModuleClasses addObject:moduleClass];
dispatch_barrier_async(RCTModuleClassesSyncQueue, ^{
[RCTModuleClasses addObject:moduleClass];
});
}
/**