make mHasDispatchScheduledCount in EventDispatcher atomic

Reviewed By: achen1

Differential Revision: D4882881

fbshipit-source-id: ac9a985287bd4720846ecde97ebb4935963c0d9f
This commit is contained in:
Aaron Chiu 2017-04-14 02:03:56 -07:00 committed by Facebook Github Bot
parent c29449d573
commit c9826ba4a9
1 changed files with 6 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import android.util.LongSparseArray;
@ -93,19 +94,19 @@ public class EventDispatcher implements LifecycleEventListener {
private final DispatchEventsRunnable mDispatchEventsRunnable = new DispatchEventsRunnable();
private final ArrayList<Event> mEventStaging = new ArrayList<>();
private final ArrayList<EventDispatcherListener> mListeners = new ArrayList<>();
private final ScheduleDispatchFrameCallback mCurrentFrameCallback =
new ScheduleDispatchFrameCallback();
private final AtomicInteger mHasDispatchScheduledCount = new AtomicInteger();
private Event[] mEventsToDispatch = new Event[16];
private int mEventsToDispatchSize = 0;
private volatile @Nullable RCTEventEmitter mRCTEventEmitter;
private final ScheduleDispatchFrameCallback mCurrentFrameCallback;
private short mNextEventTypeId = 0;
private volatile boolean mHasDispatchScheduled = false;
private volatile int mHasDispatchScheduledCount = 0;
public EventDispatcher(ReactApplicationContext reactContext) {
mReactContext = reactContext;
mReactContext.addLifecycleEventListener(this);
mCurrentFrameCallback = new ScheduleDispatchFrameCallback();
}
/**
@ -279,7 +280,7 @@ public class EventDispatcher implements LifecycleEventListener {
Systrace.startAsyncFlow(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"ScheduleDispatchFrameCallback",
mHasDispatchScheduledCount);
mHasDispatchScheduledCount.get());
mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
}
} finally {
@ -331,9 +332,8 @@ public class EventDispatcher implements LifecycleEventListener {
Systrace.endAsyncFlow(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"ScheduleDispatchFrameCallback",
mHasDispatchScheduledCount);
mHasDispatchScheduledCount.getAndIncrement());
mHasDispatchScheduled = false;
mHasDispatchScheduledCount++;
Assertions.assertNotNull(mRCTEventEmitter);
synchronized (mEventsToDispatchLock) {
// We avoid allocating an array and iterator, and "sorting" if we don't need to.