mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-10 22:45:24 +08:00
Flows between RN Threads
Reviewed By: tadeuzagallo Differential Revision: D2743733 fb-gh-sync-id: df4ae69a3501a37e08286857a8d4be3cd27c0ac3
This commit is contained in:
committed by
facebook-github-bot-3
parent
cdad5c047a
commit
e42c6d4446
@@ -56,6 +56,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
private final TraceListener mTraceListener;
|
||||
private final JavaScriptModuleRegistry mJSModuleRegistry;
|
||||
private final JSBundleLoader mJSBundleLoader;
|
||||
private volatile int mTraceID = 0;
|
||||
|
||||
// Access from native modules thread
|
||||
private final NativeModuleRegistry mJavaRegistry;
|
||||
@@ -176,12 +177,23 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
|
||||
incrementPendingJSCalls();
|
||||
|
||||
final int traceID = mTraceID++;
|
||||
Systrace.startAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
tracingName,
|
||||
traceID);
|
||||
|
||||
mCatalystQueueConfiguration.getJSQueueThread().runOnQueue(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCatalystQueueConfiguration.getJSQueueThread().assertIsOnThread();
|
||||
|
||||
Systrace.endAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
tracingName,
|
||||
traceID);
|
||||
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
@@ -208,12 +220,23 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
|
||||
incrementPendingJSCalls();
|
||||
|
||||
final int traceID = mTraceID++;
|
||||
Systrace.startAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"<callback>",
|
||||
traceID);
|
||||
|
||||
mCatalystQueueConfiguration.getJSQueueThread().runOnQueue(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCatalystQueueConfiguration.getJSQueueThread().assertIsOnThread();
|
||||
|
||||
Systrace.endAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"<callback>",
|
||||
traceID);
|
||||
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ package com.facebook.react.uimanager.events;
|
||||
*/
|
||||
public abstract class Event<T extends Event> {
|
||||
|
||||
private static int sUniqueID = 0;
|
||||
|
||||
private boolean mInitialized;
|
||||
private int mViewTag;
|
||||
private long mTimestampMs;
|
||||
private int mUniqueID = sUniqueID++;
|
||||
|
||||
protected Event() {
|
||||
}
|
||||
@@ -80,6 +83,13 @@ public abstract class Event<T extends Event> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The unique id of this event.
|
||||
*/
|
||||
public int getUniqueID() {
|
||||
return mUniqueID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the EventDispatcher is done with an event, either because it was dispatched or
|
||||
* because it was coalesced with another Event.
|
||||
|
||||
@@ -100,6 +100,7 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
private volatile @Nullable ScheduleDispatchFrameCallback mCurrentFrameCallback;
|
||||
private short mNextEventTypeId = 0;
|
||||
private volatile boolean mHasDispatchScheduled = false;
|
||||
private volatile int mHasDispatchScheduledCount = 0;
|
||||
|
||||
public EventDispatcher(ReactApplicationContext reactContext) {
|
||||
mReactContext = reactContext;
|
||||
@@ -113,6 +114,10 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");
|
||||
synchronized (mEventsStagingLock) {
|
||||
mEventStaging.add(event);
|
||||
Systrace.startAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
event.getEventName(),
|
||||
event.getUniqueID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +247,10 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
|
||||
if (!mHasDispatchScheduled) {
|
||||
mHasDispatchScheduled = true;
|
||||
Systrace.startAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"ScheduleDispatchFrameCallback",
|
||||
mHasDispatchScheduledCount);
|
||||
mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
|
||||
}
|
||||
|
||||
@@ -263,7 +272,12 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
public void run() {
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "DispatchEventsRunnable");
|
||||
try {
|
||||
Systrace.endAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"ScheduleDispatchFrameCallback",
|
||||
mHasDispatchScheduledCount);
|
||||
mHasDispatchScheduled = false;
|
||||
mHasDispatchScheduledCount++;
|
||||
Assertions.assertNotNull(mRCTEventEmitter);
|
||||
synchronized (mEventsToDispatchLock) {
|
||||
// We avoid allocating an array and iterator, and "sorting" if we don't need to.
|
||||
@@ -277,6 +291,10 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
if (event == null) {
|
||||
continue;
|
||||
}
|
||||
Systrace.endAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
event.getEventName(),
|
||||
event.getUniqueID());
|
||||
event.dispatch(mRCTEventEmitter);
|
||||
event.dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user