From c9826ba4a93f4ac4b3026c27ed0ca3668d4d0328 Mon Sep 17 00:00:00 2001 From: Aaron Chiu Date: Fri, 14 Apr 2017 02:03:56 -0700 Subject: [PATCH] make mHasDispatchScheduledCount in EventDispatcher atomic Reviewed By: achen1 Differential Revision: D4882881 fbshipit-source-id: ac9a985287bd4720846ecde97ebb4935963c0d9f --- .../react/uimanager/events/EventDispatcher.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java index 540714b2f..22e6c35f5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java @@ -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 mEventStaging = new ArrayList<>(); private final ArrayList 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.