From 11c09fdc7c442dd694909bebbbc8f21c3e69edf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Knutzen?= <2263015+hakonk@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:05:28 +0200 Subject: [PATCH] Use std::atomic for reliminating races in RCTCxxBridge --- .../React/CxxBridge/RCTCxxBridge.mm | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm index 044862f821c2a2..81172445f4f109 100644 --- a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm +++ b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm @@ -193,7 +193,7 @@ void onBatchComplete() override @implementation RCTCxxBridge { BOOL _didInvalidate; - BOOL _moduleRegistryCreated; + std::atomic _moduleRegistryCreated; NSMutableArray *_pendingCalls; std::atomic _pendingCount; @@ -220,12 +220,28 @@ @implementation RCTCxxBridge { RCTViewRegistry *_viewRegistry_DEPRECATED; RCTBundleManager *_bundleManager; RCTCallableJSModules *_callableJSModules; + std::atomic _loading; + std::atomic _valid; } @synthesize bridgeDescription = _bridgeDescription; -@synthesize loading = _loading; @synthesize performanceLogger = _performanceLogger; -@synthesize valid = _valid; + +-(BOOL)isLoading { + return _loading; +} + +-(void)setLoading:(BOOL)newValue { + _loading = newValue; +} + +-(BOOL)isValid { + return _valid; +} + +-(void)setValid:(BOOL)newValue { + _valid = newValue; +} - (RCTModuleRegistry *)moduleRegistry {