Kill UIManager lock

Summary: public

The UIManager had a lock around the enqueued ui blocks, but now all the operations
should happen on the shadow thread, so I added assertions to it and removed the
locks.

Reviewed By: nicklockwood

Differential Revision: D2605760

fb-gh-sync-id: e1bc649f759502e7e9fd059932e0cba38dba05bf
This commit is contained in:
Tadeu Zagallo 2015-11-03 03:54:23 -08:00 committed by facebook-github-bot-4
parent 27be386c2e
commit 1c9a74bbd1
1 changed files with 5 additions and 11 deletions

View File

@ -193,7 +193,6 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim
// Root views are only mutated on the shadow queue
NSMutableSet *_rootViewTags;
NSMutableArray *_pendingUIBlocks;
NSLock *_pendingUIBlocksLock;
// Animation
RCTLayoutAnimation *_nextLayoutAnimation; // RCT thread only
@ -220,8 +219,6 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls);
_shadowQueue = dispatch_queue_create("com.facebook.React.ShadowQueue", DISPATCH_QUEUE_SERIAL);
_pendingUIBlocksLock = [NSLock new];
_shadowViewRegistry = [RCTSparseArray new];
_viewRegistry = [RCTSparseArray new];
@ -253,6 +250,9 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls);
* Called on the JS Thread since all modules are invalidated on the JS thread
*/
// This only accessed from the shadow queue
_pendingUIBlocks = nil;
dispatch_async(dispatch_get_main_queue(), ^{
for (NSNumber *rootViewTag in _rootViewTags) {
[_viewRegistry[rootViewTag] invalidate];
@ -264,10 +264,6 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls);
_bridgeTransactionListeners = nil;
_bridge = nil;
[_pendingUIBlocksLock lock];
_pendingUIBlocks = nil;
[_pendingUIBlocksLock unlock];
[[NSNotificationCenter defaultCenter] removeObserver:self];
});
}
@ -439,9 +435,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls);
}
};
[_pendingUIBlocksLock lock];
[_pendingUIBlocks addObject:outerBlock];
[_pendingUIBlocksLock unlock];
}
- (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTShadowView *)rootShadowView
@ -896,13 +890,13 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po
- (void)flushUIBlocks
{
RCTAssertThread(_shadowQueue, @"flushUIBlocks can only be called from the shadow queue");
// First copy the previous blocks into a temporary variable, then reset the
// pending blocks to a new array. This guards against mutation while
// processing the pending blocks in another thread.
[_pendingUIBlocksLock lock];
NSArray *previousPendingUIBlocks = _pendingUIBlocks;
_pendingUIBlocks = [NSMutableArray new];
[_pendingUIBlocksLock unlock];
if (previousPendingUIBlocks.count) {
// Execute the previously queued UI blocks