Permalink
Browse files

RCTCxxBridge: Use C++ atomic

Summary:
The next in my series of :atom: migrations.
Closes #15277

Differential Revision: D5526460

Pulled By: javache

fbshipit-source-id: e4ba54a5911c4a76280edf8aa164ac5aa935a945
  • Loading branch information...
Adlai-Holler authored and facebook-github-bot committed Jul 31, 2017
1 parent 688c746 commit 7c528cd569b258df6e31cb76db6cca3e32cfabba
Showing with 4 additions and 6 deletions.
  1. +4 −6 React/CxxBridge/RCTCxxBridge.mm
@@ -11,7 +11,6 @@
#include <atomic>
#include <future>
#include <libkern/OSAtomic.h>
#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
@@ -135,8 +134,7 @@ @implementation RCTCxxBridge
BOOL _wasBatchActive;
NSMutableArray<dispatch_block_t> *_pendingCalls;
// This is accessed using OSAtomic... calls.
volatile int32_t _pendingCount;
std::atomic<NSInteger> _pendingCount;
// Native modules
NSMutableDictionary<NSString *, RCTModuleData *> *_moduleDataByName;
@@ -952,7 +950,7 @@ - (void)_runAfterLoad:(dispatch_block_t)block
// 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 @@ - (void)_runAfterLoad:(dispatch_block_t)block
// 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 @@ - (void)_flushPendingCalls
_pendingCalls = nil;
for (dispatch_block_t call in pendingCalls) {
call();
OSAtomicDecrement32Barrier(&_pendingCount);
_pendingCount--;
}
_loading = NO;
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");

0 comments on commit 7c528cd

Please sign in to comment.