diff --git a/BUCK b/BUCK index a2eccd5adfd..0b338cccef6 100644 --- a/BUCK +++ b/BUCK @@ -247,6 +247,7 @@ REACT_PUBLIC_HEADERS = { "React/RCTInvalidating.h": RCTBASE_PATH + "RCTInvalidating.h", "React/RCTJSScriptLoaderModule.h": RCTBASE_PATH + "RCTJSScriptLoaderModule.h", "React/RCTJSStackFrame.h": RCTBASE_PATH + "RCTJSStackFrame.h", + "React/RCTJSThread.h": RCTBASE_PATH + "RCTJSThread.h", "React/RCTJavaScriptExecutor.h": RCTBASE_PATH + "RCTJavaScriptExecutor.h", "React/RCTJavaScriptLoader.h": RCTBASE_PATH + "RCTJavaScriptLoader.h", "React/RCTKeyCommands.h": RCTBASE_PATH + "RCTKeyCommands.h", diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 3cc61733034..38b9cdd4695 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -15,6 +15,7 @@ #import "RCTInspectorDevServerHelper.h" #endif #import "RCTDevLoadingViewProtocol.h" +#import "RCTJSThread.h" #import "RCTLog.h" #import "RCTModuleData.h" #import "RCTPerformanceLogger.h" @@ -168,15 +169,9 @@ void RCTDisableTurboModuleManagerDelegateLocking(BOOL disabled) NSURL *_delegateBundleURL; } -dispatch_queue_t RCTJSThread; - + (void)initialize { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - // Set up JS thread - RCTJSThread = (id)kCFNull; - }); + _RCTInitializeJSThreadConstantInternal(); } static RCTBridge *RCTCurrentBridgeInstance = nil; diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index c823dac3dc5..fff361a58d4 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -9,6 +9,7 @@ #import #import +#import @class RCTBridge; @protocol RCTBridgeMethod; @@ -42,16 +43,6 @@ typedef void (^RCTPromiseResolveBlock)(id result); */ typedef void (^RCTPromiseRejectBlock)(NSString *code, NSString *message, NSError *error); -/** - * This constant can be returned from +methodQueue to force module - * methods to be called on the JavaScript thread. This can have serious - * implications for performance, so only use this if you're sure it's what - * you need. - * - * NOTE: RCTJSThread is not a real libdispatch queue - */ -RCT_EXTERN dispatch_queue_t RCTJSThread; - RCT_EXTERN_C_BEGIN typedef struct RCTMethodInfo { diff --git a/React/Base/RCTJSThread.h b/React/Base/RCTJSThread.h new file mode 100644 index 00000000000..8f1bc76d2c2 --- /dev/null +++ b/React/Base/RCTJSThread.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import + +#import + +/** + * This constant can be returned from +methodQueue to force module + * methods to be called on the JavaScript thread. This can have serious + * implications for performance, so only use this if you're sure it's what + * you need. + * + * NOTE: RCTJSThread is not a real libdispatch queue + */ +RCT_EXTERN dispatch_queue_t RCTJSThread; + +/** + * Initializes the RCTJSThread constant. + * Exported because the bridgeless initialization layer needs to initialize + * RCTJSThread. In bridgeless mode, RCTBridge isn't accessed, and RCTJSThread + * therefore isn't initialized. + */ +RCT_EXTERN void _RCTInitializeJSThreadConstantInternal(void); diff --git a/React/Base/RCTJSThread.m b/React/Base/RCTJSThread.m new file mode 100644 index 00000000000..192822a8606 --- /dev/null +++ b/React/Base/RCTJSThread.m @@ -0,0 +1,19 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTJSThread.h" + +dispatch_queue_t RCTJSThread; + +void _RCTInitializeJSThreadConstantInternal(void) +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + // Set up JS thread + RCTJSThread = (id)kCFNull; + }); +}