From 7c528cd569b258df6e31cb76db6cca3e32cfabba Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 31 Jul 2017 03:15:31 -0700 Subject: [PATCH] RCTCxxBridge: Use C++ atomic Summary: The next in my series of :atom: migrations. Closes https://github.com/facebook/react-native/pull/15277 Differential Revision: D5526460 Pulled By: javache fbshipit-source-id: e4ba54a5911c4a76280edf8aa164ac5aa935a945 --- React/CxxBridge/RCTCxxBridge.mm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 1314dc5db..19da6a51d 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -11,7 +11,6 @@ #include #include -#include #import #import @@ -135,8 +134,7 @@ struct RCTInstanceCallback : public InstanceCallback { BOOL _wasBatchActive; NSMutableArray *_pendingCalls; - // This is accessed using OSAtomic... calls. - volatile int32_t _pendingCount; + std::atomic _pendingCount; // Native modules NSMutableDictionary *_moduleDataByName; @@ -952,7 +950,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR // Phase 1: jsQueueBlocks are added to the queue; _pendingCount is // incremented for each. If the first block is created after self.loading is // true, phase 1 will be nothing. - OSAtomicIncrement32Barrier(&_pendingCount); + _pendingCount++; dispatch_block_t jsQueueBlock = ^{ // From the perspective of the JS queue: if (self.loading) { @@ -964,7 +962,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR // each block is executed, adding work to the queue, and _pendingCount is // decremented. block(); - OSAtomicDecrement32Barrier(&self->_pendingCount); + self->_pendingCount--; } }; [self ensureOnJavaScriptThread:jsQueueBlock]; @@ -992,7 +990,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR _pendingCalls = nil; for (dispatch_block_t call in pendingCalls) { call(); - OSAtomicDecrement32Barrier(&_pendingCount); + _pendingCount--; } _loading = NO; RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");