From f92cc5ba7785d34cfe09910c6d4e0378bb43afc2 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 28 Jan 2021 12:36:55 -0800 Subject: [PATCH] Background Executor: only cancel commit if it is for the same surface Summary: Changelog: [internal] In theory, a commit from different surface could cancel a commit for unrelated surface. Adding surfaceId to cancellation logic assures this doesn't happen. Reviewed By: shergin Differential Revision: D26126003 fbshipit-source-id: 15b9b73f1000a2b4ae882e0a5129fe26fbb53fd2 --- .../react/renderer/uimanager/UIManagerBinding.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index 4c808002b7d..2e1367be594 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -453,17 +453,17 @@ jsi::Value UIManagerBinding::get( auto shadowNodeList = shadowNodeListFromValue(runtime, arguments[1]); static std::atomic_uint_fast8_t completeRootEventCounter{0}; + static std::atomic_uint_fast32_t mostRecentSurfaceId{0}; completeRootEventCounter += 1; + mostRecentSurfaceId = surfaceId; sharedUIManager->backgroundExecutor_( - [sharedUIManager, - surfaceId, - shadowNodeList, - eventCount = completeRootEventCounter.load()] { - auto shouldCancel = [eventCount]() -> bool { + [=, eventCount = completeRootEventCounter.load()] { + auto shouldCancel = [=]() -> bool { // If `completeRootEventCounter` was incremented, another // `completeSurface` call has been scheduled and current // `completeSurface` should be cancelled. - return completeRootEventCounter > eventCount; + return completeRootEventCounter > eventCount && + mostRecentSurfaceId == surfaceId; }; sharedUIManager->completeSurface( surfaceId, shadowNodeList, {true, shouldCancel});