react-native/React/Base
Martin Kralik 02b6e38bee better event emitting II: no deadlocks
Summary:D3092867 / 1d3db4c5dc caused deadlock when chrome debugging was turned on, so it was reverted as D3128586 / 144dc30661.
The reason: I was calling `[_bridge dispatchBlock:^{ [self flushEventsQueue]; } queue:RCTJSThread];` from main thread and expecting it will `dispatch_async` to another,
since a held lock was being accessed the dispatched block and was released after the dispatch.
Turns out `RCTWebSocketExecutor` (which is used when chrome debugger is turned on) executes all blocks dispatched this way to `RCTJSThread` synchronously on the main thread.
This resulted in a deadlock. The "dispatched" block was trying to acquired lock which held by the same thread in the dispatching phase.

A fix for this is pretty simple. We will release the lock before dispatching the block.

However it's not super straightforward to see this won't introduce some race condition in a case with two threads where we would end up with events not being processed.
My thinking why that shouldn't happen goes like this: We could get in a bad state if `flushEventsQueue` would run on JS thread while `sendEvent:` is running on MT.
(I don't have a specific example how, maybe it's not possible. However when I show this case is safe we know we are good.)
The way how locking is setup in this diff the only possible scenario where these two threads would execute in these methods concurrently is JS holding the lock and MT going to enqueue another block on JS thread (since that's outside of "locked" zone).
But this scenarion can never happen, since if MT is about to enqueue the block on JS thread it means there cannot be a not yet fully executed block on JS thread.
Therefore nothing bad can happen.

So this diff brings back the reverted diff and adds to it the fix for the deadlock.

Reviewed By: javache

Differential Revision: D3130375

fb-gh-sync-id: 885a166f2f808551d7cd4e4eb98634d26afe6a11
fbshipit-source-id: 885a166f2f808551d7cd4e4eb98634d26afe6a11
2016-04-02 23:31:25 -07:00
..
RCTAssert.h Reduced work done on main thread by RCTImageLoader 2015-11-17 07:21:29 -08:00
RCTAssert.m RCTUtils Obj-C nullability annotations 2016-01-21 07:50:43 -08:00
RCTBatchedBridge.m Add more performance logs and Systrace events for RAM and bridge startup 2016-04-01 07:25:38 -07:00
RCTBridge+Private.h move `RCTBatchedBridge` interface to a private header 2016-04-01 06:54:49 -07:00
RCTBridge.h Remove unused RCTBridgeModuleClassIsRegistered 2016-03-23 17:23:20 -07:00
RCTBridge.m Add more performance logs and Systrace events for RAM and bridge startup 2016-04-01 07:25:38 -07:00
RCTBridgeDelegate.h Remove gating code for HMR on iOS 2016-02-26 09:38:01 -08:00
RCTBridgeMethod.h Prepare the bridge for C++ 2015-09-18 15:04:28 -07:00
RCTBridgeModule.h Standardize Error objects for Promises 2016-01-19 12:20:37 -08:00
RCTConvert.h Replaced RegExp method parser with recursive descent 2015-12-10 10:12:29 -08:00
RCTConvert.m backout (and remove) props.lineBreakMode from Text 2016-03-17 11:48:24 -07:00
RCTDefines.h Implement asm trampoline rather forwardInvocation 2015-10-20 04:14:09 -07:00
RCTDisplayLink.h Pull CADisplayLink into a separate file 2016-03-29 19:53:20 -07:00
RCTDisplayLink.m Pull CADisplayLink into a separate file 2016-03-29 19:53:20 -07:00
RCTEventDispatcher.h better event emitting II: no deadlocks 2016-04-02 23:31:25 -07:00
RCTEventDispatcher.m better event emitting II: no deadlocks 2016-04-02 23:31:25 -07:00
RCTFrameUpdate.h Pause JS DisplayLink if nothing to process. 2015-09-29 09:22:10 -07:00
RCTFrameUpdate.m Ran Convert > To Modern Objective C Syntax 2015-08-25 01:08:49 -08:00
RCTImageSource.h Added RCTImageSource 2015-12-08 03:32:30 -08:00
RCTImageSource.m iOS: Fix Image source={{ uri: null }} to crash 2015-12-21 10:04:31 -08:00
RCTInvalidating.h Remove isValid from RCTInvalidating 2015-08-14 01:57:18 -08:00
RCTJavaScriptExecutor.h Add context executor API for sync hooks 2016-01-05 08:00:38 -08:00
RCTJavaScriptLoader.h seek & read RAM Bundle 2016-03-17 10:35:28 -07:00
RCTJavaScriptLoader.m Extracted rootview-specific shadowview logic into new class 2016-03-21 03:21:27 -07:00
RCTKeyCommands.h
RCTKeyCommands.m Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTKeyboardObserver.h Add keyboard-observing notifications 2015-08-25 03:49:13 -08:00
RCTKeyboardObserver.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTLog.h Provide log source to handler 2015-11-11 06:44:30 -08:00
RCTLog.m Added unit tests for module init 2016-03-01 09:44:37 -08:00
RCTModuleData.h Initialize bridge on a background queue 2016-03-07 09:31:26 -08:00
RCTModuleData.m Increase RN devtools retry timeout 2016-04-01 07:02:25 -07:00
RCTModuleMethod.h Implement Android's dispatchViewManagerCommand interface on iOS 2016-01-06 05:58:37 -08:00
RCTModuleMethod.m More helpful description for native-js prop mismatch 2016-02-05 16:34:30 -08:00
RCTNullability.h Replaced RegExp method parser with recursive descent 2015-12-10 10:12:29 -08:00
RCTParserUtils.h Replaced RegExp method parser with recursive descent 2015-12-10 10:12:29 -08:00
RCTParserUtils.m Replaced RegExp method parser with recursive descent 2015-12-10 10:12:29 -08:00
RCTPerformanceLogger.h Append D3126321 2016-04-01 11:09:22 -07:00
RCTPerformanceLogger.m Append D3126321 2016-04-01 11:09:22 -07:00
RCTRootView.h remove dead code 2016-02-29 10:09:54 -08:00
RCTRootView.m Extracted rootview-specific shadowview logic into new class 2016-03-21 03:21:27 -07:00
RCTRootViewDelegate.h Prevent RCTRootView delegate call 2015-11-13 08:28:28 -08:00
RCTRootViewInternal.h Introduction of RCTRootViewDelegate 2015-10-26 15:41:36 -07:00
RCTTouchEvent.h RCTTouchEvent's init takes coalescing key 2016-04-01 06:54:49 -07:00
RCTTouchEvent.m RCTTouchEvent's init takes coalescing key 2016-04-01 06:54:49 -07:00
RCTTouchHandler.h API for cancelling RCTTouchHandler 2016-01-21 13:46:52 -08:00
RCTTouchHandler.m coalescingKeys for RCTTouchEvent 2016-04-01 06:54:50 -07:00
RCTURLRequestDelegate.h Refactored networking logic out into RCTDownloadTask 2015-07-23 04:00:31 -08:00
RCTURLRequestHandler.h [ReactNative] Refactor RCTDataManager to support pluggable data source modules (RCTURLRequestHandlers) 2015-06-09 12:27:06 -08:00
RCTUtils.h Added support for taking snapshots of the screen, window or individual views 2016-02-23 02:26:33 -08:00
RCTUtils.m Don't lose NSError code in RCTJSErrorFromNSError() 2016-03-11 02:55:22 -08:00
RCTWebSocketProxy.h Enable persistent socket between packager and bridge (1/N). 2016-02-16 23:05:36 -08:00
RCTWebSocketProxyDelegate.h Enable persistent socket between packager and bridge (1/N). 2016-02-16 23:05:36 -08:00