Skip to content

Commit

Permalink
RCTCxxBridge: Use C++ atomic
Browse files Browse the repository at this point in the history
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 7c528cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <atomic>
#include <future>
#include <libkern/OSAtomic.h>

#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
Expand Down Expand Up @@ -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, @"");
Expand Down

0 comments on commit 7c528cd

Please sign in to comment.