From beee5467790906906aa75679a9d748f65c9ac45a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 24 Jun 2019 19:04:28 -0700 Subject: [PATCH] Reduce visibility of ReactChoreographer.postFrameCallbackOnChoreographer method Summary: The method ReactChoreographer.postFrameCallbackOnChoreographer should be private and it should be called from a context that contains the lock mCallbackQueuesLock Reviewed By: JoshuaGross Differential Revision: D15891758 fbshipit-source-id: fedba0db663aade25dbad1ef7151df1e340e05f6 --- .../react/modules/core/ReactChoreographer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java index 6a8a302a3d0..071c36546fa 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java @@ -14,6 +14,7 @@ import javax.annotation.Nullable; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.common.ReactConstants; +import javax.annotation.concurrent.GuardedBy; /** * A simple wrapper around Choreographer that allows us to control the order certain callbacks @@ -78,8 +79,9 @@ public class ReactChoreographer { // This needs to be volatile due to double checked locking issue - https://fburl.com/z409owpf private @Nullable volatile ChoreographerCompat mChoreographer; private final ReactChoreographerDispatcher mReactChoreographerDispatcher; - private final ArrayDeque[] mCallbackQueues; private final Object mCallbackQueuesLock = new Object(); + @GuardedBy("mCallbackQueuesLock") + private final ArrayDeque[] mCallbackQueues; private int mTotalCallbacks = 0; private boolean mHasPostedCallback = false; @@ -116,7 +118,11 @@ public class ReactChoreographer { } } - public void postFrameCallbackOnChoreographer() { + /** + * This method writes on mHasPostedCallback and it should be called from another method that + * has the lock mCallbackQueuesLock + */ + private void postFrameCallbackOnChoreographer() { mChoreographer.postFrameCallback(mReactChoreographerDispatcher); mHasPostedCallback = true; } @@ -150,6 +156,10 @@ public class ReactChoreographer { } } + /** + * This method reads and writes on mHasPostedCallback and it should be called from another method + * that already has the lock mCallbackQueuesLock. + */ private void maybeRemoveFrameCallback() { Assertions.assertCondition(mTotalCallbacks >= 0); if (mTotalCallbacks == 0 && mHasPostedCallback) {